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

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuchen.saas.manage.system.api.param.CommonIdParam;
import com.yuchen.saas.park.api.dto.property.PropertyShareFeeQryDto;
import com.yuchen.saas.park.api.dto.property.PropertyShareFeeSaveDto;
import com.yuchen.saas.park.api.vo.property.PropertyShareFeeDetailListVo;
import com.yuchen.saas.park.api.vo.property.PropertyShareFeeListVo;
import com.yuchen.saas.park.service.service.property.PropertyShareFeeDetailService;
import com.yuchen.saas.park.service.service.property.PropertyShareFeeService;
import com.yuchen.saas.park.service.service.property.SaasParkPropertyHandHouseMeterProbablyService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nest.springwrap.core.tool.api.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * <p>
 * 手动抄表-房屋抄表-房源仪表抄表概况 前端控制器
 * </p>
 *
 * @author miaoqs
 * @since 2024-09-30
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/saasParkPropertyHandHouseMeterProbably")
public class SaasParkPropertyHandHouseMeterProbablyController {

    private final SaasParkPropertyHandHouseMeterProbablyService saasParkPropertyHandHouseMeterProbablyService;

    @Resource
    private PropertyShareFeeService propertyShareFeeService;
    @Resource
    private PropertyShareFeeDetailService propertyShareFeeDetailService;


    @PostMapping("/saveShareFee")
    @ApiOperation(value = "房源仪表抄表概况保存")
    public R saveShareFee(@Valid @RequestBody PropertyShareFeeSaveDto shareFeeSaveDto) {
        propertyShareFeeService.saveShareFee(shareFeeSaveDto);
        return R.success();
    }

    @PostMapping("/list")
    @ApiOperation(value = "列表")
    public R<Page<PropertyShareFeeListVo>> list(@RequestBody PropertyShareFeeQryDto shareFeeQryDto) {
        return R.data(propertyShareFeeService.selectPage(shareFeeQryDto));
    }

    @PostMapping("/detail")
    @ApiOperation(value = "详情")
    public R<PropertyShareFeeSaveDto> detail(@Valid @RequestBody CommonIdParam param) {
        return R.data(propertyShareFeeService.getShareFeeDetail(param.getId()));
    }

    @GetMapping("/detailList")
    @ApiOperation(value = "明细列表")
    public R<Page<PropertyShareFeeDetailListVo>> detailList(@RequestParam("shareFeeId") String shareFeeId,
                                                            @RequestParam(value = "current", defaultValue = "1") Integer current,
                                                            @RequestParam(value = "size", defaultValue = "10") Integer size) {
        return R.data(propertyShareFeeDetailService.selectPage(shareFeeId,current,size));
    }

    @PostMapping("/delete")
    @ApiOperation(value = "删除")
    public R delete(@Valid @RequestBody CommonIdParam param) {
        propertyShareFeeService.deleteShareFee(param.getId());
        return R.success();
    }

    @PostMapping("/share")
    @ApiOperation(value = "分摊")
    public R share(@Valid @RequestBody CommonIdParam param) {
        propertyShareFeeService.share(param.getId());
        return R.success();
    }


}
