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

import com.baomidou.mybatisplus.core.metadata.IPage;
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.entity.property.SaasParkPropertyPublicMeter;
import com.yuchen.saas.park.api.request.SaasParkPropertyBuildingMeterChangeRequest;
import com.yuchen.saas.park.api.request.SaasParkPropertyPublicMeterChangeRequest;
import com.yuchen.saas.park.api.request.SaasParkPropertyPublicMeterRequest;
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.SaasParkPropertyPublicMeterService;
import io.swagger.annotations.ApiOperation;
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;

/**
 * <p>
 * 仪表管理-公摊仪表 前端控制器
 * </p>
 *
 * @author miaoqs
 * @since 2024-09-30
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/saasParkPropertyPublicMeter")
public class SaasParkPropertyPublicMeterController {

    private final SaasParkPropertyPublicMeterService saasParkPropertyPublicMeterService;

    /**
     * 公摊仪表 新增/修改
     * @param publicMeter
     * @return
     */
    @PostMapping("/saveOrUpdate")
    @ApiOperation(value = "公摊仪表 新增/修改")
    public R saveShareFee(@Valid @RequestBody SaasParkPropertyPublicMeter publicMeter) {
        saasParkPropertyPublicMeterService.saveOrUpdate(publicMeter);
        return R.success();
    }

    /**
     * 公摊仪表 列表
     * @param req
     * @return
     */
    @PostMapping("/pageByparam")
    @ApiOperation(value = "公摊仪表 列表")
    public R<NestPage<SaasParkPropertyPublicMeter>> pageByparam(@RequestBody SaasParkPropertyPublicMeterRequest req) {
        IPage<SaasParkPropertyPublicMeter> pages = saasParkPropertyPublicMeterService.pageByparam(req);
        return R.data(NestPage.of(pages));
    }

    /**
     * 公摊仪表 详情
     * @param publicMeter
     * @return
     */
    @PostMapping("/detail")
    @ApiOperation(value = "公摊仪表 详情")
    public R<SaasParkPropertyPublicMeter> detail(@Valid @RequestBody SaasParkPropertyPublicMeter publicMeter) {
        return R.data(saasParkPropertyPublicMeterService.getById(publicMeter.getId()));
    }

    /**
     * 公摊仪表 删除
     * @param publicMeter
     * @return
     */
    @PostMapping("/delete")
    @ApiOperation(value = "公摊仪表 删除")
    public R delete(@Valid @RequestBody SaasParkPropertyPublicMeter publicMeter) {
        // TODO 被引用后不能删除 ，待确认引用的表
        saasParkPropertyPublicMeterService.removeById(publicMeter.getId());
        return R.success();
    }

    /**
     * 公摊仪表 更换仪表
     * @param changeMeter
     * @return
     */
    @PostMapping("/changeMeter")
    @ApiOperation(value = "公摊仪表 更换仪表")
    public R changeMeter(@Valid @RequestBody SaasParkPropertyPublicMeterChangeRequest changeMeter) {
        saasParkPropertyPublicMeterService.changeMeter(changeMeter);
        return R.success();
    }



}
