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.stockScan.AddStockScanReq;
import org.wcs.model.dto.serve.stockScan.QueryStockScanReq;
import org.wcs.model.dto.serve.stockScan.UpdateStockScanReq;
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.stockScan.AppBaseScanMethodVo;
import org.wcs.model.vo.serve.stockScan.AppStockScanVo;
import org.wcs.serve.service.intf.IStockScanService;

import java.util.List;

/**
 * 扫码相关
 */
@RestController
@RequestMapping("/app/stockScan")
@ResponseBody
@RequiredArgsConstructor
public class StockScanController {

    private final IStockScanService stockScanService;

    /**
     * 分页查询扫码设置信息
     * @param request 查询参数
     * @param pageSize 每页数量
     * @param pageIndex 当前页码
     * @return 查询结果
     */
    @PostMapping("/queryWithPage")
    public AppServeDataResponse<PageDataResponse<AppStockScanVo>> queryStockScan(@RequestBody QueryStockScanReq request, @RequestParam("pageSize") Integer pageSize, @RequestParam("pageIndex") Integer pageIndex) {
        return stockScanService.queryStockScan(request, pageSize, pageIndex);
    }

    @GetMapping("/queryAll")
    public AppServeDataResponse<List<AppStockScanVo>> queryStockScanAll() {
        return stockScanService.queryStockScan();
    }

    /**
     * 查询基础扫码方式
     * @return 查询结果
     */
    @GetMapping("/queryBaseScanMethod")
    public AppServeDataResponse<List<AppBaseScanMethodVo>> queryBaseScanMethod() {
        return stockScanService.queryBaseScanMethod();
    }

    /**
     * 新增仓库扫码
     * @param request 新增参数
     * @return 新增结果
     */
    @PostMapping("/addStockScan")
    public AppServeResponse addStockScan(@RequestBody @Validated AddStockScanReq request) {
        return stockScanService.addStockScan(request);
    }

    /**
     * 修改仓库扫码
     * @param request 修改参数
     * @return 修改结果
     */
    @PostMapping("/updateStockScan")
    public AppServeResponse updateStockScan(@RequestBody @Validated UpdateStockScanReq request) {
        return stockScanService.updateStockScan(request);
    }

    /**
     * 删除仓库扫码
     * @param stockScanId 仓库扫码ID
     * @return 删除结果
     */
    @DeleteMapping("/deleteStockScan")
    public AppServeResponse deleteStockScan(@RequestParam("stockScanId") @NotBlank(message = "仓库扫码ID不能为空") String stockScanId) {
        return stockScanService.deleteStockScan(stockScanId);
    }

}
