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

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yuchen.saas.park.api.entity.property.SaasParkPropertyBillChargeSetup;
import com.yuchen.saas.park.api.request.SaasParkPropertyBillChargeSetupReq;
import com.yuchen.saas.park.service.service.property.SaasParkPropertyAutoPublicMeterReadingService;
import com.yuchen.saas.park.service.service.property.SaasParkPropertyBillChargeSetupService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nest.springwrap.core.tool.api.R;
import org.nest.springwrap.core.tool.utils.Func;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 自动抄表-公摊抄表 前端控制器
 * </p>
 *
 * @author miaoqs
 * @since 2024-09-30
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/saasParkPropertyAutoPublicMeterReading")
public class SaasParkPropertyAutoPublicMeterReadingController {

    private final SaasParkPropertyAutoPublicMeterReadingService saasParkPropertyAutoPublicMeterReadingService;

    private final SaasParkPropertyBillChargeSetupService propertyBillChargeSetupService;

    /**
     * 账单收费设置 新增或修改
     */
    @PostMapping("/saveOrUpdate")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "账单收费设置 新增或修改", notes = "账单收费设置 新增或修改")
    public R saveOrUpdate(@Valid @RequestBody SaasParkPropertyBillChargeSetup propertyBillChargeSetup) {
        if(Func.isEmpty(propertyBillChargeSetup)) {
            return R.error("账单收费设置不能为空");
        }
        return R.data(propertyBillChargeSetupService.saveOrUpdateByParam(propertyBillChargeSetup));
    }

    /**
     * 获取详情
     * @param id
     * @return
     */
    @GetMapping("/detail")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "账单收费设置 详情", notes = "账单收费设置详情")
    public R detail(Long id) {
        return R.data(propertyBillChargeSetupService.getById(id));
    }

    /**
     * 根据主表id删除账单收费设置
     * @param propertyBillChargeSetup
     * @return
     */
    @PostMapping("/removeId")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "根据主表id 账单收费设置 删除", notes = "根据主表id 账单收费设置 删除")
    public R removeId(@RequestBody SaasParkPropertyBillChargeSetup propertyBillChargeSetup) {
        propertyBillChargeSetupService.removeById(propertyBillChargeSetup.getId());
        return R.success();
    }

    @GetMapping("/detailByParkIdAndCommunityId")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "根据项目和社区获取配置详情", notes = "根据项目和社区获取配置详情")
    public R detailByParkIdAndCommunityId(SaasParkPropertyBillChargeSetupReq propertyBillChargeSetupReq) {
        if(Func.isEmpty(propertyBillChargeSetupReq) || Func.isEmpty(propertyBillChargeSetupReq.getParkId())
                || Func.isEmpty(propertyBillChargeSetupReq.getCommunityId())){
            return R.error("项目和社区不能为空");
        }
        return R.data(propertyBillChargeSetupService.detailByParkIdAndCommunityId(propertyBillChargeSetupReq));
    }

}
