#[cfg(feature = "reqwest")]
use reqwest;

use snafu::Backtrace;
use {ommui_file_loading, uuid};

#[derive(Debug, Snafu)]
#[snafu(visibility(pub(crate)))]
pub enum Error {
    #[snafu(display("Item '{}' of kind '{}' not found", id, kind))]
    NotFound {
        kind: &'static str,
        id: String,
        backtrace: Backtrace,
    },

    #[snafu(display("Error parsing uuid from {:?}: {}", raw, source))]
    ParseUuid {
        raw: String,
        source: uuid::parser::ParseError,
        backtrace: Backtrace,
    },

    #[cfg(feature = "reqwest")]
    #[snafu(display("Error from reqwest: {}", source))]
    Reqwest {
        source: reqwest::Error,
        backtrace: Backtrace,
    },

    #[snafu(display("Error reading response from {}: {}", url, source))]
    ReadResponse {
        url: String,
        source: std::io::Error,
        backtrace: Backtrace,
    },

    #[snafu(display(
        "Error parsing integer value from {:?}: {}",
        raw,
        source
    ))]
    ParseInt {
        raw: String,
        source: std::num::ParseIntError,
        backtrace: Backtrace,
    },

    #[snafu(display("{}", source))]
    #[snafu(backtrace(delegate))]
    OmmuiFileLoading { source: ommui_file_loading::Error },
}
