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

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yuchen.saas.park.api.entity.property.SaasParkPropertyBuildingMeter;
import com.yuchen.saas.park.api.request.SaasParkPropertyBuildingMeterChangeRequest;
import com.yuchen.saas.park.api.request.SaasParkPropertyBuildingMeterRequest;
import com.yuchen.saas.park.service.service.property.SaasParkPropertyBuildingMeterService;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

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

    private final SaasParkPropertyBuildingMeterService saasParkPropertyBuildingMeterService;

    /**
     * 房屋仪表 新增/修改
     * @param buildingMeter
     * @return
     */
    @PostMapping("/saveOrUpdate")
    @ApiOperation(value = "房屋仪表 新增/修改")
    public R saveShareFee(@Valid @RequestBody SaasParkPropertyBuildingMeter buildingMeter) {
        saasParkPropertyBuildingMeterService.saveOrUpdate(buildingMeter);
        return R.success();
    }

    /**
     * 房屋仪表 列表
     * @param req
     * @return
     */
    @PostMapping("/pageByparam")
    @ApiOperation(value = "房屋仪表 列表")
    public R<NestPage<SaasParkPropertyBuildingMeter>> pageByparam(@RequestBody SaasParkPropertyBuildingMeterRequest req) {
        IPage<SaasParkPropertyBuildingMeter> pages = saasParkPropertyBuildingMeterService.pageByparam(req);
        return R.data(NestPage.of(pages));
    }

    /**
     * 房屋仪表 详情
     * @param buildingMeter
     * @return
     */
    @PostMapping("/detail")
    @ApiOperation(value = "房屋仪表 详情")
    public R<SaasParkPropertyBuildingMeter> detail(@Valid @RequestBody SaasParkPropertyBuildingMeter buildingMeter) {
        return R.data(saasParkPropertyBuildingMeterService.getById(buildingMeter.getId()));
    }

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

    /**
     * 房屋仪表 更换仪表
     * @param changeMeter
     * @return
     */
    @PostMapping("/changeMeter")
    @ApiOperation(value = "房屋仪表 更换仪表")
    public R changeMeter(@Valid @RequestBody SaasParkPropertyBuildingMeterChangeRequest changeMeter) {
        saasParkPropertyBuildingMeterService.changeMeter(changeMeter);
        return R.success();
    }

}
