pub mod codegen;
pub mod edge_resolver;
pub mod graph_generator;
pub mod ncl_parser;
pub mod node_types;

use std::fmt;

#[derive(Debug)]
pub enum BuildError {
    NiclCommand(String),
    NclExport { path: String, stderr: String },
    NclParse(String),
    Io(std::io::Error),
    Json(serde_json::Error),
    MissingEnv(&'static str),
    Glob(String),
}

impl fmt::Display for BuildError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::NiclCommand(e) => write!(f, "nickel command failed: {e}"),
            Self::NclExport { path, stderr } => {
                write!(f, "nickel export failed for {path}: {stderr}")
            }
            Self::NclParse(e) => write!(f, "NCL JSON parse error: {e}"),
            Self::Io(e) => write!(f, "I/O error: {e}"),
            Self::Json(e) => write!(f, "JSON error: {e}"),
            Self::MissingEnv(v) => write!(f, "missing env var: {v}"),
            Self::Glob(e) => write!(f, "glob error: {e}"),
        }
    }
}

impl std::error::Error for BuildError {}

impl From<std::io::Error> for BuildError {
    fn from(e: std::io::Error) -> Self {
        Self::Io(e)
    }
}
impl From<serde_json::Error> for BuildError {
    fn from(e: serde_json::Error) -> Self {
        Self::Json(e)
    }
}
