package com.cf.imes.module.executor.controller.admin.veneer;

import com.cf.imes.framework.common.pojo.CommonResult;
import com.cf.imes.framework.common.pojo.PageResult;
import com.cf.imes.module.executor.controller.admin.veneer.vo.UnplannedVeneerPlateDataReqVO;
import com.cf.imes.module.executor.controller.admin.veneer.vo.UnplannedVeneerPlateDataRespVO;
import com.cf.imes.module.executor.controller.admin.veneer.vo.VeneerManageGoodsPageReqVO;
import com.cf.imes.module.executor.controller.admin.veneer.vo.VeneerManageGoodsRespVO;
import com.cf.imes.module.executor.controller.admin.veneer.vo.VeneerManageOrderPageReqVO;
import com.cf.imes.module.executor.controller.admin.veneer.vo.VeneerManageOrderRespVO;
import com.cf.imes.module.executor.service.veneer.VeneerManageService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static com.cf.imes.framework.common.pojo.CommonResult.success;

/**
 * 未排贴皮接口。
 */
@Tag(name = "生产管理 - 未排贴皮")
@RestController
@RequestMapping("/executor/unplanned-veneer")
@Validated
public class UnplannedVeneerController {

    @Resource
    private VeneerManageService veneerManageService;

    /**
     * 分页查询存在未排贴皮的订单。
     *
     * @param req 分页及筛选条件
     * @return 订单分页列表
     */
    @PostMapping("/order/page")
    @Operation(summary = "获取未排贴皮订单分页列表")
    @PreAuthorize("@ss.hasPermission('unplannedOrders:query')")
    public CommonResult<PageResult<VeneerManageOrderRespVO>> getUnplannedVeneerOrderPage(
            @Valid @RequestBody VeneerManageOrderPageReqVO req) {
        return success(veneerManageService.getUnplannedOrderPage(req));
    }

    /**
     * 分页查询存在未排贴皮的板材。
     *
     * @param req 分页及筛选条件
     * @return 板材分页列表
     */
    @PostMapping("/goods/page")
    @Operation(summary = "获取未排贴皮板材分页列表")
    @PreAuthorize("@ss.hasPermission('unplannedOrders:query')")
    public CommonResult<PageResult<VeneerManageGoodsRespVO>> getUnplannedVeneerGoodsPage(
            @Valid @RequestBody VeneerManageGoodsPageReqVO req) {
        return success(veneerManageService.getUnplannedGoodsPage(req));
    }

    /**
     * 按订单或板材查询未排贴皮、原板件及板件造型数据。
     *
     * @param req 互斥查询范围及可选房间、柜体条件
     * @return 未排贴皮排单基础数据
     */
    @PostMapping("/plate/data")
    @Operation(summary = "获取未排贴皮板件数据")
    @PreAuthorize("@ss.hasPermission('unplannedOrders:query')")
    public CommonResult<UnplannedVeneerPlateDataRespVO> getUnplannedVeneerPlateData(
            @Valid @RequestBody UnplannedVeneerPlateDataReqVO req) {
        return success(veneerManageService.getUnplannedPlateData(req));
    }
}
