package com.cf.imes.module.manage.controller.admin.process;


import com.cf.imes.framework.common.pojo.CommonResult;
import com.cf.imes.framework.common.pojo.PageResult;
import com.cf.imes.module.manage.controller.admin.process.vo.*;
import com.cf.imes.module.manage.controller.admin.query.vo.productionStatus.OrderModuleVO;
import com.cf.imes.module.manage.controller.admin.query.vo.productionStatus.OrderPlateRespVO;
import com.cf.imes.module.manage.controller.admin.query.vo.productionStatus.PlatePageVO;
import com.cf.imes.module.manage.service.process.ProductionProcessService;
import com.cf.imes.module.manage.service.query.ProductionStatusService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

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

@Tag(name = "管理后台 - 生产单工序")
@RestController
@RequestMapping("/manage/process")
@Validated
public class ProductionProcessController {


    @Resource
    private ProductionProcessService productionProcessService;

    @Resource
    private ProductionStatusService productionStatusService;





    @GetMapping("/page")
    @Operation(summary = "查看生产工序分页")
    @PreAuthorize("@ss.hasPermission('manage:process:query')")
    public CommonResult<PageResult<ProcessRespVO>> getUserPage(@Valid ProcessPageReqVO pageReqVO) {

        return success(productionProcessService.getProcessPage(pageReqVO));


    }




    @PutMapping("/update")
    @Operation(summary = "修改生产工序明细和步骤表的状态")
    @PreAuthorize("@ss.hasPermission('manage:process:update')")
    public  CommonResult<Boolean> updateProcessStatus(@Valid @RequestBody OrderProcessStepItemVO reqVo){
        productionProcessService.updateProcessStatus(reqVo);
        return success(true);

    }



    @GetMapping("/selectPlate")
    @Operation(summary = "查看当前生产单的工序对应的板件信息")
    public CommonResult<OrderPlateReqVO>  selectPlate(@Valid ProcessPlateReqVO reqVO){
        return success(productionProcessService.selectPlate(reqVO));
    }




//    @GetMapping("/selectBodyName")
//    @Operation(summary = "查询生产单对应的柜体名称")
    public CommonResult<List<OrderBodyRespVo>> selectBodyName(@Valid OrderBodyReqVO reqVO){
        return success(productionProcessService.selectBodyName(reqVO));

    }





//    @GetMapping("/selectPlateName")
//    @Operation(summary = "查看板材信息的组合名称")
//    @Parameter(name = "stepItemId", description = "工序明细ID", required = true, example = "1")
//    @PreAuthorize("@ss.hasPermission('manage:process:query')")
    public CommonResult<List<OrderModuleVO>> selectPlateName(@Valid @RequestParam("stepItemId") Long stepItemId){


        return success(productionProcessService.selectPlateName(stepItemId));

    }



//
//    @GetMapping("/pagePlate")
//    @Operation(summary = "查看板材信息分页")
//    @PreAuthorize("@ss.hasPermission('manage:process:query')")
    public CommonResult<PageResult<OrderPlateRespVO>> queryPlate(@Valid PlatePageVO pageReqVO){
        return success(productionStatusService.getOrderPlatePage(pageReqVO));
    }


}
