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

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yuchen.saas.park.api.entity.pldoor.PlSpWarning;
import com.yuchen.saas.park.api.vo.request.PlSpRobotScreenReq;
import com.yuchen.saas.park.api.vo.request.PlSpWarningReq;
import com.yuchen.saas.park.service.service.pldoor.PlSpWarningService;
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.nest.springwrap.core.tool.utils.Func;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 巡逻告警 前端控制器
 * </p>
 *
 * @author miaoqs
 * @since 2024-08-16
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/plSpWarning")
public class PlSpWarningController {

    private final PlSpWarningService plSpWarningService;

    /**
     * 巡逻告警 新增或修改
     */
    @PostMapping("/saveOrUpdate")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "巡逻告警 新增或修改", notes = "巡逻告警 新增或修改")
    public R saveOrUpdate(@Valid @RequestBody PlSpWarning plSpWarning) {
        if(Func.isEmpty(plSpWarning)) {
            return R.error("巡逻告警不能为空");
        }
        return R.data(plSpWarningService.saveOrUpdate(plSpWarning));
    }

    /**
     * 获取详情
     * @param id
     * @return
     */
    @GetMapping("/detail")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "巡逻告警 详情", notes = "巡逻告警详情")
    public R detail(Long id) {
        return R.data(plSpWarningService.getById(id));
    }

    /**
     * 根据主表id删除巡逻告警
     * @param plSpWarning
     * @return
     */
    @PostMapping("/removeId")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "根据主表id 巡逻告警 删除", notes = "根据主表id 巡逻告警 删除")
    public R removeId(@RequestBody PlSpWarning plSpWarning) {
        plSpWarningService.removeById(plSpWarning.getId());
        return R.success();
    }

    /**
     * 分页 巡逻告警
     */
    @GetMapping("/pageByparam")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "分页 巡逻告警", notes = "分页 巡逻告警")
    public R<NestPage<PlSpWarning>> pageByparam(PlSpWarningReq plSpWarningReq, Query query) {
        IPage<PlSpWarning> pages = plSpWarningService.pageByparam(plSpWarningReq, query);
        return  R.data(NestPage.of(pages));
    }

    /* @PostMapping("/updateOrderState")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "修改启用状态", notes = "修改启用状态")
    public R updateOrderState(@Valid @RequestBody PlSpWarning plSpWarning) {
        if(Func.isEmpty(plSpWarning) || Func.isEmpty(plSpWarning.getTaskState())) {
            return R.error("启用状态不能为空");
        }
        plSpWarning.setId(plSpWarning.getId());
        plSpWarning.setTaskState(plSpWarning.getTaskState());
        return R.data(plSpWarningService.updateById(plSpWarning));
    } */
}
