package vip.xiaonuo.coldchain.modular.monitordevicepower.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import vip.xiaonuo.coldchain.modular.monitordevice.entity.MonitorDevice;
import vip.xiaonuo.coldchain.modular.monitordevice.param.MonitorDeviceAddParam;
import vip.xiaonuo.coldchain.modular.monitordevice.param.MonitorDeviceEditParam;
import vip.xiaonuo.coldchain.modular.monitordevice.param.MonitorDeviceIdParam;
import vip.xiaonuo.coldchain.modular.monitordevicepower.entity.MonitorDevicePower;
import vip.xiaonuo.coldchain.modular.monitordevicepower.param.MonitorDevicePowerAddParam;
import vip.xiaonuo.coldchain.modular.monitordevicepower.param.MonitorDevicePowerEditParam;
import vip.xiaonuo.coldchain.modular.monitordevicepower.param.MonitorDevicePowerIdParam;
import vip.xiaonuo.coldchain.modular.monitordevicepower.param.MonitorDevicePowerPageParam;
import vip.xiaonuo.coldchain.modular.monitordevicepower.service.MonitorDevicePowerService;
import vip.xiaonuo.common.annotation.CommonLog;
import vip.xiaonuo.common.pojo.CommonResult;

import java.util.List;

@Tag(name = "电源管理控制器")
@RestController
@Validated
public class MonitorDevicePowerController {

    @Resource
    MonitorDevicePowerService monitorDevicePowerService;

    /**
     * 获取电源管理分页
     */
    @Operation(summary = "获取电源管理分页")
    @SaCheckPermission("/coldchain/monitordevicepower/page")
    @GetMapping("/coldchain/monitordevicepower/page")
    public CommonResult<Page<MonitorDevicePower>> page(MonitorDevicePowerPageParam monitorDevicePowerPageParam) {
        return CommonResult.data(monitorDevicePowerService.page(monitorDevicePowerPageParam));
    }

    /**
     * 添加电源管理
     */
    @Operation(summary = "添加电源管理")
    @CommonLog("添加电源管理")
    @SaCheckPermission("/coldchain/monitordevicepower/add")
    @PostMapping("/coldchain/monitordevicepower/add")
    public CommonResult<String> add(@RequestBody @Valid MonitorDevicePowerAddParam monitorDevicePowerAddParam) {
        monitorDevicePowerService.add(monitorDevicePowerAddParam);
        return CommonResult.ok();
    }

    /**
     * 编辑电源管理
     */
    @Operation(summary = "编辑电源管理")
    @CommonLog("编辑电源管理")
    @SaCheckPermission("/coldchain/monitordevicepower/edit")
    @PostMapping("/coldchain/monitordevicepower/edit")
    public CommonResult<String> edit(@RequestBody @Valid MonitorDevicePowerEditParam monitorDevicePowerEditParam) {
        monitorDevicePowerService.edit(monitorDevicePowerEditParam);
        return CommonResult.ok();
    }

    /**
     * 删除电源管理
     */
    @Operation(summary = "删除电源管理")
    @CommonLog("删除电源管理")
    @SaCheckPermission("/coldchain/monitordevicepower/delete")
    @PostMapping("/coldchain/monitordevicepower/delete")
    public CommonResult<String> delete(@RequestBody @Valid @NotEmpty(message = "集合不能为空")
                                       List<MonitorDevicePowerIdParam> monitorDevicePowerIdParamList) {
        monitorDevicePowerService.delete(monitorDevicePowerIdParamList);
        return CommonResult.ok();
    }

    /**
     * 获取电源管理详情
     */
    @Operation(summary = "获取电源管理详情")
    @SaCheckPermission("/coldchain/monitordevicepower/detail")
    @GetMapping("/coldchain/monitordevicepower/detail")
    public CommonResult<MonitorDevicePower> detail(@Valid MonitorDevicePowerIdParam monitorDevicePowerIdParam) {
        return CommonResult.data(monitorDevicePowerService.detail(monitorDevicePowerIdParam));
    }

    /**
     * 获取电源列表
     */
    @Operation(summary = "获取电源列表")
    @SaCheckPermission("/coldchain/monitordevicepower/list")
    @GetMapping("/coldchain/monitordevicepower/list")
    public CommonResult<List<MonitorDevicePower>> list() {
        return CommonResult.data(monitorDevicePowerService.myList());
    }
}
