package org.wcs.serve.controller.app;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.wcs.model.dto.serve.stacker.AddOrUpdateStackerStandReq;
import org.wcs.model.dto.serve.stacker.AddStackerReq;
import org.wcs.model.dto.serve.stacker.UpdateStackerInfoReq;
import org.wcs.model.vo.serve.AppServeDataResponse;
import org.wcs.model.vo.serve.AppServeResponse;
import org.wcs.model.vo.serve.stacker.QueryStackerInfoVo;
import org.wcs.model.vo.serve.stacker.QueryStackerStandVo;
import org.wcs.model.vo.serve.stacker.StackerStatusVo;
import org.wcs.serve.service.intf.IStackerService;

import java.util.List;

/**
 * 堆垛机相关控制器
 */
@RestController
@RequestMapping("/app/stacker")
@ResponseBody
@RequiredArgsConstructor
public class StackerController {

    private final IStackerService stackerService;

    /**
     * 查询堆垛机信息
     * @param stackerName 堆垛机名称
     * @return 查询结果
     */
    @GetMapping("/queryStackerInfo")
    public AppServeDataResponse<List<QueryStackerInfoVo>> queryStackerInfo(@RequestParam("stackerName") String stackerName) {
        return stackerService.queryStackerInfo(stackerName);
    }

    /**
     * 添加堆垛机
     * @param addStackerReq 添加堆垛机请求参数
     * @return 添加结果
     */
    @PostMapping("/addStackerInfo")
    public AppServeResponse addStackerInfo(@RequestBody @Validated AddStackerReq addStackerReq) {
        return stackerService.addStacker(addStackerReq);
    }

    /**
     * 更新堆垛机信息
     * @param updateStackerInfoReq 更新堆垛机请求参数
     * @return 更新结果
     */
    @PostMapping("/updateStackerInfo")
    public AppServeResponse updateStackerInfo(@RequestBody @Validated UpdateStackerInfoReq updateStackerInfoReq) {
        return stackerService.updateStackerInfo(updateStackerInfoReq);
    }

    /**
     * 查询堆垛机的站台
     * @param stackerId  堆垛机ID
     * @return  查询结果
     */
    @GetMapping("/queryStackerStand")
    public AppServeDataResponse<List<QueryStackerStandVo>> queryStackerStand(@RequestParam("stackerId") @NotNull(message =  "堆垛机ID不能为空") Integer stackerId) {
        return stackerService.queryStackerStand(stackerId);
    }

    /**
     * 新增或修改堆垛机站台
     * @param addOrUpdateStackerStandReq  堆垛机站台
     * @return  操作结果
     */
    @PostMapping("/addOrUpdateStackerStand")
    public AppServeResponse addOrUpdateStackerStand(@RequestBody @Validated AddOrUpdateStackerStandReq addOrUpdateStackerStandReq) {
        return stackerService.addOrUpdateStackerStand(addOrUpdateStackerStandReq);
    }

    /**
     * 删除堆垛机站台
     * @param standId  堆垛机站台ID
     * @return  操作结果
     */
    @DeleteMapping("/deleteWithStandId/{standId}")
    public AppServeResponse deleteWithStandId(@PathVariable @NotBlank(message = "堆垛机站台ID不能为空") String standId) {
        return stackerService.deleteWithStandId(standId);
    }

    /**
     * 获取堆垛机运行信息
     * @return  堆垛机运行信息
     */
    @GetMapping("/getStackerRunningInfo")
    public AppServeDataResponse<List<StackerStatusVo>> getStackerRunningInfo() {
        return stackerService.getStackerRunningInfo();
    }



}
