use miette::Diagnostic;
use quick_xml::events::Event;
use snafu::Backtrace;
use snafu::Snafu;

pub(crate) mod parser;
pub mod types;

#[derive(Debug, Diagnostic, Snafu)]
pub enum XmlError {
    #[snafu(context(false))]
    InvalidUtf8 {
        backtrace: Backtrace,

        source: core::str::Utf8Error,
    },

    #[snafu(context(false))]
    Parser {
        backtrace: Backtrace,

        source: quick_xml::Error,
    },

    #[snafu(display("unexpected token: found {received:?} while expecting {expected}"))]
    UnexpectedToken {
        backtrace: Backtrace,

        expected: String,
        received: Event<'static>,
    },
}

type XmlResult<T, E = XmlError> = Result<T, E>;