package com.aps.entity.basic;


import com.aps.entity.Algorithm.OperationDependency;
import com.aps.entity.Algorithm.OrderMaterialRequirement;
import com.aps.entity.RoutingDiscreteParam;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

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

/**
 * 作者：佟礼
 * 时间：2025-11-21
 */
@Data
public class Entry {
    public Entry() {
        prevEntryIds=new ArrayList<OperationDependency>();

    }
    /**
     * 基因编号
     */
    private int id ;
    /**
     * 所属组ID 需要按照前后顺序生产的工单给一组
     */
    private int groupId ;
    /**
     * 原订单ID
     */
    private String orderId ;

    private String orderCode ;


    private String sceneId ;
    private Integer routingId;
    private String routingCode;
    private String routingName;
    /** 部门ID，来自工艺路线 routing_header.department_id，在创建 Entry 时从工艺头带出 */
    private Integer departmentId;
    private Long routingDetailId;
    private Long taskSeq;
    private String routingDetailName;


    private String productId;
    private String productCode;
    private String productName;
    /**
     * 工单ID
     */
    private String execId ;

    /**
     * 工单ID
     */
    private String mainId;

    /**
     * 拆分来源ID：当state=1时，记录原始工序的id，用于识别同一原始工序的拆分子工序
     */
    private transient Integer splitSourceId;

    /**
     * 离散参数
     */
    private List<RoutingDiscreteParam> discreteParameter ;
    /**
     * 基因编号
     */
    private double priority=1;
    /**
     * 数量
     */
    private double quantity;
    /**
     * 工序顺序
     */
    private int sequence;

    private double minProcessingTime; // 加工时间 (秒)

    /**
     * 可选设备列表
     */
    private List<MachineOption> MachineOptions ;

    /**
     * 选择的设备
     */
    private Long  SelectMachineID ;

    /**
     * 前工单ID
     */
    private List<OperationDependency> prevEntryIds ;//前工序

    /**
     * 后工单ID
     */
    private List<OperationDependency> nextEntryIds ;//后工序

    /**
     * 数据状态 1 拆分 2 新建
     */
    private Integer state ;

/**
 * 是否可中断，间缝插针
 */
private Long isInterrupt = 1l;

    /**
     * 所需物料
     */
    private List<OrderMaterialRequirement> materialRequirements ; // 所需物料



    /**
     * 设备资源组
     */

    private Long  equipTypeID ;

    /// <summary>
    /// 当前工序依赖的前置工序ID（半成品工序→成品工序）
    /// </summary>
    private List<Integer> dependentOnOrderIds =new ArrayList<>();



    /// <summary>
    /// 关联的成品工序ID（核心：明确该半成品服务于哪个成品工序）
    /// </summary>
    private List<Integer> targetFinishedOperationId;

    private boolean newCreate = false;

    /// <summary>
    /// 半成品最晚完工时间（即成品工序开始时间-1天）
    /// </summary>
    private LocalDateTime latestCompletionTime ;


    private String equipTypeName;//资源组名称
    private String equipTypeCode;//资源组编码
    private BigDecimal runtime;//持续时间
    private BigDecimal singleOut;//单件产出
    private double changeLineTime;//换模时间
    private BigDecimal setupTime;//准备时间
    private int teardownTime; // （后处理时间）
    private int preTime; // （前处理时间）
    //常数时间
    private int constTime;
    private String equipCode;//设备编码
    private String equipName;//设备编码



    @Schema(description = "指定开始时间")
    @JsonInclude(JsonInclude.Include.ALWAYS)
    private LocalDateTime designatedStartTime;

    private LocalDateTime jitPreferredStartTime;

    private boolean jitTemporary = false;

    private String schedulingMode = SchedulingMode.FORWARD.name();

    private int anchorTimeSecond = 0;

    private transient boolean backwardFailed = false;

    private transient boolean scheduled = false;

    private transient Integer actualFinishTime;

    public enum SchedulingMode {
        FORWARD, BACKWARD
    }
}
