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.PlPsRobotEquipment;
import com.yuchen.saas.park.api.vo.request.PlSpRobotEquipmentReq;
import com.yuchen.saas.park.service.service.pldoor.PlPsRobotEquipmentService;
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>
 * 机器人配送终端(Mc 机器人注册) 前端控制器
 * </p>
 *
 * @author miaoqs
 * @since 2024-11-01
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/plPsRobotEquipment")
public class PlPsRobotEquipmentController {

    private final PlPsRobotEquipmentService plPsRobotEquipmentService;

    /**
     * 机器人配送终端 新增或修改
     */
    @PostMapping("/saveOrUpdate")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "机器人配送终端 新增或修改", notes = "机器人配送终端 新增或修改")
    public R saveOrUpdate(@Valid @RequestBody PlPsRobotEquipment plPsRobotEquipment) {
        if(Func.isEmpty(plPsRobotEquipment)) {
            return R.error("机器人配送终端不能为空");
        }
        return R.data(plPsRobotEquipmentService.saveOrUpdate(plPsRobotEquipment));
    }

    /**
     * 获取详情
     * @param id
     * @return
     */
    @GetMapping("/detail")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "机器人配送终端 详情", notes = "机器人配送终端详情")
    public R detail(Long id) {
        return R.data(plPsRobotEquipmentService.getById(id));
    }

    /**
     * 根据主表id删除机器人配送终端
     * @param plPsRobotEquipment
     * @return
     */
    @PostMapping("/removeId")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "根据主表id 机器人配送终端 删除", notes = "根据主表id 机器人配送终端 删除")
    public R removeId(@RequestBody PlPsRobotEquipment plPsRobotEquipment) {
        plPsRobotEquipmentService.removeById(plPsRobotEquipment.getId());
        return R.success();
    }

    /**
     * 分页 机器人配送终端
     */
    @GetMapping("/pageByparam")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "分页 机器人配送终端", notes = "分页 机器人配送终端")
    public R<NestPage<PlPsRobotEquipment>> pageByparam(PlPsRobotEquipment plPsRobotEquipment, Query query) {
        IPage<PlPsRobotEquipment> pages = plPsRobotEquipmentService.pageByparam(plPsRobotEquipment, query);
        return  R.data(NestPage.of(pages));
    }


}
