package com.aps.macroplanner.variable;

import com.google.ortools.linearsolver.MPSolver;
import com.aps.macroplanner.data.*;
import com.aps.macroplanner.model.MacroPlannerModel;

/**
 * 需求满足量变量构建器 — 创建 DemandFulfillmentInPISPIP 变量。
 *
 * <p>DemandFulfillmentInPISPIP[productId_spId_periodIndex] — PISPIP 总需求满足量</p>
 * <ul>
 *   <li>含义: 某个产品/库存点/周期内所有需求的总满足量</li>
 *   <li>用途: 安全库存天数计算的基础 — 库存 ≥ 未来N天需求满足量</li>
 *   <li>组成: SalesDemandQty + OperationDemandQty (BOM消耗)</li>
 *   <li>范围: [0, +∞)</li>
 * </ul>
 */
public class DemandFulfillmentVariableBuilder {

    public static void create(MacroPlannerModel model, TestDataBuilder data) {
        double inf = MPSolver.infinity();
        for (Product prod : data.getProducts()) {
            for (StockingPoint sp : data.getStockingPointsForProduct(prod.getId())) {
                for (Period p : data.getPeriods()) {
                    String key = prod.getId() + "_" + sp.getId() + "_" + p.getIndex();
                    model.getDemandFulfillmentVars().put(key,
                            model.getSolver().makeNumVar(0.0, inf, "DFulfill_" + key));
                }
            }
        }
    }
}