package com.aps.macroplanner.data;

/**
 * 单元周期 (UnitPeriod) — 对应 Quintiq 中的 UnitPeriod
 * 表示某个单元在某个周期的产能可用情况
 */
public class UnitPeriod {
    private final String unitId;
    private final Period period;
    private final double minCapacity;    // 最小产能
    private final double maxCapacity;    // 最大可用产能
    private final boolean hasMinCapacity; // 是否有最小产能约束
    private final boolean unlimited;      // 产能是否无上限 (如原材料供应商)

    /** 完整构造器 */
    public UnitPeriod(String unitId, Period period, double minCapacity, double maxCapacity,
                      boolean hasMinCapacity, boolean unlimited) {
        this.unitId = unitId;
        this.period = period;
        this.minCapacity = minCapacity;
        this.maxCapacity = unlimited ? Double.MAX_VALUE : maxCapacity;
        this.hasMinCapacity = hasMinCapacity;
        this.unlimited = unlimited;
    }

    /** 有限产能构造器 (向后兼容) */
    public UnitPeriod(String unitId, Period period, double minCapacity, double maxCapacity, boolean hasMinCapacity) {
        this(unitId, period, minCapacity, maxCapacity, hasMinCapacity, false);
    }

    /** 无限产能便捷构造器 */
    public static UnitPeriod unlimited(String unitId, Period period) {
        return new UnitPeriod(unitId, period, 0, 0, false, true);
    }

    public String getUnitId() { return unitId; }
    public Period getPeriod() { return period; }
    public double getMinCapacity() { return minCapacity; }
    public double getMaxCapacity() { return maxCapacity; }
    public boolean hasMinCapacity() { return hasMinCapacity; }
    public boolean isUnlimited() { return unlimited; }

    public String getKey() {
        return unitId + "_" + period.getIndex();
    }

    @Override
    public String toString() {
        return "UnitPeriod[" + unitId + ", " + period + "]";
    }
}