//! Enum error definition

use syn::{Generics, Ident};

use super::VariantDefinition;

/// A validated error enum definition ready for code generation
#[derive(Debug, Clone)]
pub(crate) struct EnumDefinition {
    /// The name of the error enum
    pub(crate) name: Ident,

    /// Generic parameters of the enum
    pub(crate) generics: Generics,

    /// The error variants
    pub(crate) variants: Vec<VariantDefinition>,
}

impl EnumDefinition {
    /// Validate the error definition
    pub(crate) fn validate(&self) -> syn::Result<()> {
        if self.variants.is_empty() {
            return Err(syn::Error::new_spanned(
                &self.name,
                "error enum must have at least one variant",
            ));
        }

        for variant in &self.variants {
            variant.validate()?;
        }

        Ok(())
    }
}
