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.SaasParkPropertyMeterType;
import com.yuchen.saas.park.api.request.SaasParkPropertyMeterTypeRequest;
import com.yuchen.saas.park.api.vo.property.PropertyShareFeeDetailListVo;
import com.yuchen.saas.park.api.vo.property.PropertyShareFeeListVo;
import com.yuchen.saas.park.api.vo.request.PlDoorPointReq;
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.SaasParkPropertyMeterTypeService;
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.mp.support.Query;
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-29
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/saasParkPropertyMeterType")
public class SaasParkPropertyMeterTypeController {

    private final SaasParkPropertyMeterTypeService saasParkPropertyMeterTypeService;

    /**
     * 仪表类型 新增/修改
     * @param meterType
     * @return
     */
    @PostMapping("/saveOrUpdate")
    @ApiOperation(value = "仪表类型 新增/修改")
    public R saveShareFee(@Valid @RequestBody SaasParkPropertyMeterType meterType) {
        saasParkPropertyMeterTypeService.saveOrUpdate(meterType);
        return R.success();
    }

    /**
     * 仪表类型 列表
     * @param req
     * @return
     */
    @PostMapping("/pageByparam")
    @ApiOperation(value = "仪表类型 列表")
    public R<NestPage<SaasParkPropertyMeterType>> pageByparam(@RequestBody SaasParkPropertyMeterTypeRequest req) {
        IPage<SaasParkPropertyMeterType> pages = saasParkPropertyMeterTypeService.pageByparam(req);
        return R.data(NestPage.of(pages));
    }

    /**
     * 仪表类型 详情
     * @param meterType
     * @return
     */
    @PostMapping("/detail")
    @ApiOperation(value = "仪表类型 详情")
    public R<SaasParkPropertyMeterType> detail(@Valid @RequestBody SaasParkPropertyMeterType meterType) {
        return R.data(saasParkPropertyMeterTypeService.getById(meterType.getId()));
    }

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

}
