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

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yuchen.saas.park.api.entity.property.SaasParkPropertyMeterReadingSet;
import com.yuchen.saas.park.api.request.SaasParkPropertyMeterReadingSetRequest;
import com.yuchen.saas.park.service.service.property.SaasParkPropertyMeterReadingSetService;
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.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-29
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/saasParkPropertyMeterReadingSet")
public class SaasParkPropertyMeterReadingSetController {

    private final SaasParkPropertyMeterReadingSetService meterReadingSetService;

    /**
     * 抄表设置 新增/修改
     * @param meterReadingSet
     * @return
     */
    @PostMapping("/saveOrUpdate")
    @ApiOperation(value = "抄表设置 新增/修改")
    public R saveShareFee(@Valid @RequestBody SaasParkPropertyMeterReadingSet meterReadingSet) {
        meterReadingSetService.saveOrUpdate(meterReadingSet);
        return R.success();
    }

    /**
     * 抄表设置 列表
     * @param request
     * @return
     */
    @PostMapping("/pageByparam")
    @ApiOperation(value = "抄表设置 列表")
    public R<NestPage<SaasParkPropertyMeterReadingSet>> pageByparam(@RequestBody SaasParkPropertyMeterReadingSetRequest request) {
        IPage<SaasParkPropertyMeterReadingSet> pages = meterReadingSetService.pageByparam(request);
        return R.data(NestPage.of(pages));
    }

    /**
     * 抄表设置 详情
     * @param meterReadingSet
     * @return
     */
    @PostMapping("/detail")
    @ApiOperation(value = "抄表设置 详情")
    public R<SaasParkPropertyMeterReadingSet> detail(@Valid @RequestBody SaasParkPropertyMeterReadingSet meterReadingSet) {
        return R.data(meterReadingSetService.getById(meterReadingSet.getId()));
    }

    /**
     * 抄表设置 删除
     * @param meterReadingSet
     * @return
     */
    @PostMapping("/delete")
    @ApiOperation(value = "抄表设置 删除")
    public R delete(@Valid @RequestBody SaasParkPropertyMeterReadingSet meterReadingSet) {
        meterReadingSetService.removeById(meterReadingSet.getId());
        return R.success();
    }
}
