pmat 3.11.0

PMAT - Zero-config AI context generation and code quality toolkit (CLI, MCP, HTTP)
#![cfg_attr(coverage_nightly, coverage(off))]

use std::collections::{HashMap, HashSet};

use super::grade::{MetricCategory, PenaltyAttribution};

pub struct PenaltyTracker {
    applied: HashMap<String, PenaltyAttribution>,
}

impl Default for PenaltyTracker {
    fn default() -> Self {
        Self::new()
    }
}

impl PenaltyTracker {
    #[must_use]
    pub fn new() -> Self {
        Self {
            applied: HashMap::new(),
        }
    }

    pub fn apply(
        &mut self,
        issue_id: String,
        category: MetricCategory,
        amount: f32,
        issue: String,
    ) -> Option<f32> {
        if self.applied.contains_key(&issue_id) {
            return None;
        }

        self.applied.insert(
            issue_id,
            PenaltyAttribution {
                source_metric: category,
                amount,
                applied_to: HashSet::from([category]),
                issue,
            },
        );

        Some(amount)
    }

    #[must_use]
    pub fn get_attributions(&self) -> Vec<PenaltyAttribution> {
        self.applied.values().cloned().collect()
    }
}