use forge::budget::SignalBudget;
use serde_json::Value;

#[derive(Debug, Clone)]
pub struct SkillInput {
    pub params: Value,
}

impl SkillInput {
    pub fn new(params: Value) -> Self {
        Self { params }
    }
    pub fn from_value(v: Value) -> Self {
        Self { params: v }
    }

    pub fn get(&self, key: &str) -> Option<&Value> {
        self.params.get(key)
    }

    pub fn get_str(&self, key: &str) -> Option<&str> {
        self.params.get(key).and_then(|v| v.as_str())
    }
    pub fn get_u64(&self, key: &str) -> Option<u64> {
        self.params.get(key).and_then(|v| v.as_u64())
    }
    pub fn get_bool(&self, key: &str) -> Option<bool> {
        self.params.get(key).and_then(|v| v.as_bool())
    }
    pub fn get_str_array(&self, key: &str) -> Option<Vec<String>> {
        self.params.get(key)?.as_array().map(|arr| {
            arr.iter()
                .filter_map(|v| v.as_str().map(|s| s.to_string()))
                .collect()
        })
    }
}

#[derive(Clone)]
pub struct SkillContext {
    pub session_id: String,
    pub working_dir: String,
    pub budget: SignalBudget,
    pub task_hint: Option<String>,
}

impl SkillContext {
    pub fn new(session_id: impl Into<String>, working_dir: impl Into<String>) -> Self {
        Self {
            session_id: session_id.into(),
            working_dir: working_dir.into(),
            budget: SignalBudget::new(8_000),
            task_hint: None,
        }
    }
}
