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.PlSpRobotEquipment;
import com.yuchen.saas.park.api.vo.request.PlSpPatrolTaskReq;
import com.yuchen.saas.park.api.vo.request.PlSpRobotEquipmentReq;
import com.yuchen.saas.park.service.service.pldoor.PlSpRobotEquipmentService;
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("/plSpRobotEquipment")
public class PlSpRobotEquipmentController {

    private final PlSpRobotEquipmentService plSpRobotEquipmentService;

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

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

    /**
     * 根据主表id删除巡逻终端
     * @param plSpRobotEquipment
     * @return
     */
    @PostMapping("/removeId")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "根据主表id 巡逻终端 删除", notes = "根据主表id 巡逻终端 删除")
    public R removeId(@RequestBody PlSpRobotEquipment plSpRobotEquipment) {
        plSpRobotEquipmentService.removeById(plSpRobotEquipment.getId());
        return R.success();
    }

    /**
     * 分页 巡逻终端
     */
    @GetMapping("/pageByparam")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "分页 巡逻终端", notes = "分页 巡逻终端")
    public R<NestPage<PlSpRobotEquipment>> pageByparam(PlSpRobotEquipmentReq plSpRobotEquipmentReq, Query query) {
        IPage<PlSpRobotEquipment> pages = plSpRobotEquipmentService.pageByparam(plSpRobotEquipmentReq, query);
        return  R.data(NestPage.of(pages));
    }

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

}
