use serde::{Deserialize, Serialize};
use std::path::PathBuf;

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Rule {
    /// Source file the rule came from (e.g. `/proj/.botignore`).
    pub source: PathBuf,
    /// Pattern text as it appeared in the source.
    pub pattern: String,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Reason {
    pub message: String,
    pub rule: Option<Rule>,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(tag = "kind", rename_all = "lowercase")]
pub enum Decision {
    Allow,
    Ask(Reason),
    Deny(Reason),
}

impl Decision {
    pub fn is_blocking(&self) -> bool {
        matches!(self, Decision::Deny(_))
    }
}
