package com.yuchen.saas.park.service.controller.property;


import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yuchen.saas.manage.system.api.param.CommonIdParam;
import com.yuchen.saas.park.api.dto.property.*;
import com.yuchen.saas.park.api.entity.property.PropertyPublicMeter;
import com.yuchen.saas.park.api.vo.property.*;
import com.yuchen.saas.park.service.service.property.IPropertyPublicMeterService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nest.springwrap.core.mp.support.NestPage;
import org.nest.springwrap.core.tool.api.R;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 公摊仪表 前端控制器
 * </p>
 *
 * @author cxj
 * @since 2023-11-23
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/propertyPublicMeter")
public class PropertyPublicMeterController {

    private final IPropertyPublicMeterService baseService;

    @GetMapping("getPage")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "分页获取仪表类型", notes = "分页获取仪表类型")
    public R<NestPage<PropertyPublicMeterPageVo>> list(PropertyPublicMeterQueryDto dto) {
        NestPage<PropertyPublicMeterPageVo> page = baseService.getPage(dto);
        return R.data(page);
    }

    @GetMapping("getPageBySelect")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "总表分页下拉", notes = "总表分页下拉")
    public R<NestPage<PropertyPublicMeter>> getPageBySelect(PropertyPublicMeterQuerySelectDto dto) {
        NestPage<PropertyPublicMeter> page = baseService.getPageBySelect(dto);
        return R.data(page);
    }

    @GetMapping("/getHouseMeter")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "获取房源仪表详情(更换仪表)", notes = "获取房源仪表详情(更换仪表)")
    public R<PropertyPublicMeterDetailVo> getHouseMeterById(@ApiParam(value = "id") @RequestParam Long id) {
        return R.data(baseService.getHouseMeterById(id));
    }

    @PostMapping("/addOrUpdate")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "新增/编辑", notes = "新增/编辑")
    public R addOrUpdate(@Valid @RequestBody PropertyPublicMeterAddDto dto) {
        return R.status(baseService.addOrUpdate(dto));
    }

    @PostMapping("/binding")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "绑定收费标准", notes = "绑定收费标准")
    public R binding(@Valid @RequestBody List<PropertyMeterBindingDto> list) {
        return R.status(baseService.binding(list));
    }

    @PostMapping("/delete")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "删除", notes = "删除")
    public R delete(@Valid @RequestBody CommonIdParam param) {
        return R.status(baseService.del(param.getId()));
    }

    @PostMapping("/updateMeter")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "更换仪表", notes = "更换仪表")
    public R updateMeter(@Valid @RequestBody PropertyPublicMeterUpdateDto dto) {
        return R.status(baseService.updateMeter(dto));
    }

    @PostMapping("/updateIsSealed")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "启用/禁用", notes = "启用/禁用")
    public R updateIsSealed(@Valid @RequestBody PropertyMeterUpdateIsSealedDto dto) {
        return R.status(baseService.updateIsSealed(dto));
    }

    @GetMapping("getListByApp")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "小程序获取仪表类型列表-公摊", notes = "小程序获取仪表类型列表-公摊")
    public R<List<PropertyPublicMeterAppPageVo>> getListByApp(@Valid PropertyHouseMeterAppQueryDto dto) {
        List<PropertyPublicMeterAppPageVo> page = baseService.getListByApp(dto);
        return R.data(page);
    }

    @GetMapping("getDetailByApp")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "小程序抄表详情-公摊", notes = "小程序抄表详情-公摊")
    public R<PropertyPublicMeterReadingByAppVo> getDetailByApp(@ApiParam(value = "id") @RequestParam Long id) {
        PropertyPublicMeterReadingByAppVo vo = baseService.getDetailByApp(id);
        return R.data(vo);
    }
}
