package com.aps.macroplanner.output.dto;

import java.util.ArrayList;
import java.util.List;

/**
 * KPI 汇总结果 — 对应 Quintiq 中 OptimizerNonFinancialKPIResult 的快照数据。
 */
public class KpiResult {

    /** 目标函数值 (加权总惩罚) */
    private double objectiveValue;

    /** 各项 KPI 明细 */
    private final List<KpiEntry> entries = new ArrayList<>();

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

    /** 单个 KPI 项 */
    public static class KpiEntry {
        /** KPI 名称 */
        public String name;
        /** KPI 原始值 (松弛量总和) */
        public double rawValue;
        /** 权重 */
        public double weight;
        /** 加权惩罚 = rawValue × weight */
        public double penalty;
        /** 是否为收益项 (越大越好, 正系数) */
        public boolean isBenefit;
    }

    // ==================== Getters / Setters ====================

    public double getObjectiveValue() { return objectiveValue; }
    public void setObjectiveValue(double v) { this.objectiveValue = v; }

    public List<KpiEntry> getEntries() { return entries; }

    public void addEntry(String name, double rawValue, double weight, boolean isBenefit) {
        KpiEntry e = new KpiEntry();
        e.name = name;
        e.rawValue = rawValue;
        e.weight = weight;
        e.isBenefit = isBenefit;
        e.penalty = isBenefit ? -rawValue * weight : rawValue * weight;
        entries.add(e);
    }
}