package com.aps.macroplanner.output.dto;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * 单个设备的产能使用结果 — 由 {@code ResultWriter.buildUnitCapacities()} 计算。
 *
 * <h3>字段说明</h3>
 * <table>
 *   <tr><td>unitId</td><td>设备ID</td></tr>
 *   <tr><td>operationIds</td><td>使用该设备的工序ID列表</td></tr>
 *   <tr><td>totalMaxCapacity</td><td>该设备在全部周期的最大可用产能合计(小时)</td></tr>
 *   <tr><td>totalCapacityUsed</td><td>该设备在全部周期的实际产能占用合计(小时)</td></tr>
 *   <tr><td>totalUtilizationRate</td><td>整体设备利用率 = totalCapacityUsed / totalMaxCapacity</td></tr>
 *   <tr><td>totalProduction</td><td>该设备全部周期产出合计</td></tr>
 *   <tr><td>periodDetails</td><td>各周期明细 (UnitPeriodDetail[])</td></tr>
 *   <tr><td>periodTasks</td><td>该设备的生产任务明细 (PeriodTaskResult[])</td></tr>
 * </table>
 */
public class UnitCapacityResult {

    /** 设备ID */
    private String unitId;
    /** 使用该设备的工序ID列表 */
    private List<String> operationIds;
    /** 全部周期最大可用产能合计 */
    private double totalMaxCapacity;
    /** 全部周期实际产能占用合计 */
    private double totalCapacityUsed;
    /** 整体设备利用率 = totalCapacityUsed / totalMaxCapacity */
    private double totalUtilizationRate;
    /** 全部周期产出合计 */
    private double totalProduction;


    private double totalOverloaded;
    private double totalNotMet;
    private double overallUtilization;

    /** 各周期明细 */
    private final List<UnitPeriodDetail> periodDetails = new ArrayList<>();


    // ==================== 内嵌类 ====================

    /** 单周期产能明细 */
    public static class UnitPeriodDetail {
        /** 周期索引 */
        public int periodIndex;
        /** 周期起始日期 */
        public String periodStartDate;
        /** 该周期最大可用产能(小时) */
        public double maxCapacity;
        /** 该周期实际产能占用(小时) */
        public double capacityUsed;

        /** 该周期设备利用率 = capacityUsed / maxCapacity */
        public double utilization;
        public double overloaded;
        public double notMet;

        /** 该周期产出 */
        public double production;

        /** 该周期内在该设备上执行的工序明细 */
        public final List<UnitTaskInfo> tasks = new ArrayList<>();
    }
    /** 设备上的工序级生产明细 */
    public static class UnitTaskInfo {
        public String operationId;
        public String operationName;
        public double productionQty;
        public double capacityUsed;
        public double capacityCoeff;
        public Double lotSize;
        public double lotSizeOver;
        public double lotSizeUnder;
        /** 产出: productId@spId */
        public final List<String> outputs = new ArrayList<>();
    }
    // ==================== Getters / Setters ====================

    public String getUnitId() { return unitId; }
    public void setUnitId(String v) { this.unitId = v; }

    public List<String> getOperationIds() { return operationIds; }
    public void setOperationIds(List<String> v) { this.operationIds = v; }

    public double getTotalMaxCapacity() { return totalMaxCapacity; }
    public void setTotalMaxCapacity(double v) { this.totalMaxCapacity = v; }

    public double getTotalCapacityUsed() { return totalCapacityUsed; }
    public void setTotalCapacityUsed(double v) { this.totalCapacityUsed = v; }

    public double getTotalUtilizationRate() { return totalUtilizationRate; }
    public void setTotalUtilizationRate(double v) { this.totalUtilizationRate = v; }

    public double getTotalProduction() { return totalProduction; }
    public void setTotalProduction(double v) { this.totalProduction = v; }

    public List<UnitPeriodDetail> getPeriodDetails() { return periodDetails; }

    public double getTotalOverloaded() { return totalOverloaded; }
    public void setTotalOverloaded(double v) { this.totalOverloaded = v; }

    public double getTotalNotMet() { return totalNotMet; }
    public void setTotalNotMet(double v) { this.totalNotMet = v; }

    public double getOverallUtilization() { return overallUtilization; }
    public void setOverallUtilization(double v) { this.overallUtilization = v; }
}
