package org.wcs.serve.controller.app;

import jakarta.validation.constraints.NotBlank;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.wcs.model.dto.serve.convey.AddConveyLocationReq;
import org.wcs.model.dto.serve.convey.QueryConveyLocationReq;
import org.wcs.model.dto.serve.convey.UpdateConveyLocationReq;
import org.wcs.model.vo.serve.AppServeDataResponse;
import org.wcs.model.vo.serve.AppServeResponse;
import org.wcs.model.vo.serve.common.PageDataResponse;
import org.wcs.model.vo.serve.convey.ConveyStatusVo;
import org.wcs.model.vo.serve.convey.QueryConveyLocationVo;
import org.wcs.serve.service.intf.IConveyLocationService;


@RestController
@RequestMapping("/app/conveyLocation")
@ResponseBody
@RequiredArgsConstructor
public class ConveyLocationController {

    private final IConveyLocationService conveyLocationService;

    /**
     * 分页查询输送线点位信息
     * @param request 查询请求
     * @param pageSize 每页大小
     * @param pageIndex 页码
     * @return 查询结果
     */
    @PostMapping("queryConveyLocation")
    public AppServeDataResponse<PageDataResponse<QueryConveyLocationVo>> queryConveyLocation(@RequestBody QueryConveyLocationReq request, @RequestParam("pageSize") Integer pageSize, @RequestParam("pageIndex") Integer pageIndex) {
        return conveyLocationService.queryConveyLocation(request, pageSize, pageIndex);
    }

    /**
     * 新增输送点位
     * @param request 新增参数
     * @return 新增结果
     */
    @PostMapping("addConveyLocation")
    public AppServeResponse addConveyLocation(@RequestBody @Validated AddConveyLocationReq request) {
        return conveyLocationService.addConveyLocation(request);
    }

    /**
     * 更新输送数据
     * @param request 更新的数据
     * @return 更新结果
     */
    @PostMapping("updateConveyLocation")
    public AppServeResponse updateConveyLocation(@RequestBody @Validated UpdateConveyLocationReq request) {
        return conveyLocationService.updateConveyLocation(request);
    }

    /**
     * 查询输送点位状态
     * @param conveyId 查询的输送机编号
     * @return 结果
     */
    @GetMapping("queryConveyLocationStatus")
    public AppServeDataResponse<ConveyStatusVo> queryTrayConveyStatus(@RequestParam("conveyId") @NotBlank(message = "输送点位ID不能为空") String conveyId) {
        return conveyLocationService.queryTrayConveyStatus(conveyId);
    }

}
