use dashmap::DashMap;
use std::sync::Arc;

/// Per-surface in-memory state held by the agent. Tracks an opaque
/// "report token" identifying the last report we issued a patch
/// against so we don't double-propose against the same render. The
/// token shape is the agent's business; the state just stores it.
///
/// In-memory by design — agents don't typically touch
/// `car-state::StateStore`. Learned strategies live in memgine.
#[derive(Default, Clone)]
pub struct DecisionState {
    last_decision_token: Arc<DashMap<String, String>>,
}

impl DecisionState {
    pub fn new() -> Self {
        Self::default()
    }

    pub fn already_decided_with(&self, surface_id: &str, token: &str) -> bool {
        self.last_decision_token
            .get(surface_id)
            .map(|v| v.as_str() == token)
            .unwrap_or(false)
    }

    pub fn record(&self, surface_id: &str, token: String) {
        self.last_decision_token
            .insert(surface_id.to_string(), token);
    }

    pub fn reset(&self, surface_id: &str) {
        self.last_decision_token.remove(surface_id);
    }
}
