package com.cf.imes.module.executor.dal.dataobject.goods;


import com.cf.imes.module.executor.controller.admin.plan.saveOptimize.ActualGoodsList;
import com.cf.imes.module.executor.controller.admin.plan.saveOptimize.RemainBoardList;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;


@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Schema(description = "优化后的大板信息")
public class OptimizeBoardModelDO {

    @Schema(description = "排单ID")
    private Long planId;


    @Schema(description = "订单id")
    @JsonFormat(with = JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
    private List<Long> orderId;


    @Schema(description = "方案组的ID")
    private Long processId;


    @Schema(description = "方案组的配置项ID")
    private Long planConfigId;


    @Schema(description = "方案组的配置项名称")
    private String planConfigName;


    @Schema(description = "是否锁定排单")
    private Boolean isLock;


    @Schema(description = "是否有新加入的小板")
    private Boolean isNewInsertPlate;


    @Schema(description = "实际的开料的大板的ID")
    @JsonFormat(with = JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
    private List<String> goodsId;


    @Schema(description = "原板材信息的大板ID")
    @JsonFormat(with = JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
    private List<String> mixGoodsIds;


    @Schema(description = "订单已优化小板数量")
    private Long placeBlockNumber;


    @Schema(description = "已开料大板数量")
    private Long cutedBoardNumber;


    @Schema(description = "已开料的小板数量")
    private Long cutedBlockNumber;


    // 新的数据集需要去除
    @Schema(description = "排单优化的大板数量")
    private Long placeBoardNumber;


    @Schema(description = "已开料大板数据集")
    @JsonFormat(with = JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
    private List<CutedBoardInfo> cutedBoardInfo;


    @Schema(description = "大板原长")
    private BigDecimal orgLength;
    @Schema(description = "大板原宽")
    private BigDecimal orgWidth;


    @Schema(description = "大板开料长")
    private BigDecimal length;
    @Schema(description = "大板开料宽")
    private BigDecimal width;
    @Schema(description = "大板厚度")
    private BigDecimal thickness;

    @Schema(description = "修边值")
    private BigDecimal cutBorder;


    @Schema(description = "开料刀直径")
    private BigDecimal diameter;


    @Schema(description = "开料刀路间隙")
    private BigDecimal cutKnifeGap;


    @Schema(description = "预铣值")
    private BigDecimal preMillingSize;


    @Schema(description = "是否辅助开料")
    private Boolean isHelpCut;


    @Schema(description = "同刀辅助开料偏移")
    private BigDecimal helpCutGap;


    @Schema(description = "开料刀ID")
    private Integer cutKnifeId;



    @Schema(description = "辅助刀ID")
    private Integer helpKnifeId;



    @Schema(description = "是否已优化")
    private Boolean isOptimized;


    @Schema(description = "大板数")
    private Integer boardCount;


    @Schema(description = "余料板数")
    private Integer remainBoardCount;


    @Schema(description = "最小板号")
    private Integer minBoardId;


    @Schema(description = "最大板号")
    private Integer maxBoardId;


    @Schema(description = "总平均利用率")
    private BigDecimal avgUsageRateAll;


    @Schema(description = "前N块板(不包含最后一块板)的平均利用率")
    private BigDecimal avgUsageRateExcludeLastBoard;



    @Schema(description = "最后一块板的利用率")
    private BigDecimal usageRateLastBoard;



    @Schema(description = "使用大板情况--大板优化数据")
    private String usedBoardInfo;



    @Schema(description = "小板排版情况--小板优化数据")
    private String blockPlaceInfo;



    @Schema(description = "余料板排版情况--余料板优化数据")
    private String remainBoardInfo;



    @Schema(description = "余料板的数据列表")
    private List<RemainBoardList> remainBoardList;


    @Schema(description = "大板板材列表-实际的开料的大板信息")
    private List<ActualGoodsList> actualGoodsList;


    // 处理 remainBoardList = " " 的情况
    public void setRemainBoardList(Object remainBoardList) {
        if (remainBoardList instanceof String && ((String) remainBoardList).isEmpty()) {
            this.remainBoardList = new ArrayList<>();
        } else if (remainBoardList instanceof List) {
            this.remainBoardList = (List<RemainBoardList>) remainBoardList;
        } else {
            this.remainBoardList = new ArrayList<>();
        }
    }

}
