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.vo.property.PropertyHouseMeterAppPageVo;
import com.yuchen.saas.park.api.vo.property.PropertyHouseMeterDetailVo;
import com.yuchen.saas.park.api.vo.property.PropertyHouseMeterPageVo;
import com.yuchen.saas.park.api.vo.property.PropertyHouseMeterReadingByAppVo;
import com.yuchen.saas.park.service.service.property.IPropertyHouseMeterService;
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.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

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

/**
 * <p>
 * 房间仪表 前端控制器
 * </p>
 *
 * @author cxj
 * @since 2023-11-21
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/propertyHouseMeter")
@Validated
public class PropertyHouseMeterController {

    private final IPropertyHouseMeterService baseService;

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

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


    @PostMapping("/addList")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "批量新增", notes = "批量新增")
    public R addList(@Valid @RequestBody PropertyHouseMeterAddListDto dto) {
        return R.status(baseService.addList(dto));
    }

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

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

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

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

    @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<PropertyHouseMeterAppPageVo>> getListByApp(@Valid PropertyHouseMeterAppQueryDto dto) {
        List<PropertyHouseMeterAppPageVo> page = baseService.getListByApp(dto);
        return R.data(page);
    }

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

}
