// Generated by scripts/generate-holidays.py

use std::fmt::Display;
use std::str::FromStr;

use super::UnknownCountryCode;

/// An enum for selecting a country.
///
/// ```
/// use opening_hours::localization::Country;
///
/// let country: Country = "FR".parse().unwrap();
/// assert_eq!(country, Country::FR);
/// ```
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub enum Country {
    {%- for country in countries %}
    /// {{ country.name }}
    {{ country.iso_code }},
    {%- endfor %}
}

impl Country {
    pub const ALL: [Self; {{ countries | length }}] = [
        {%- for country in countries %}
        Self::{{ country.iso_code }},
        {%- endfor %}
    ];

    /// Get the country's full name.
    ///
    /// ```
    /// use opening_hours::localization::Country;
    ///
    /// assert_eq!(Country::FR.name(), "France");
    /// ```
    pub fn name(self) -> &'static str {
        match self {
            {%- for country in countries %}
            Self::{{ country.iso_code }} => "{{ country.name }}",
            {%- endfor %}
        }
    }

    /// Get the country's iso code.
    ///
    /// ```
    /// use opening_hours::localization::Country;
    ///
    /// assert_eq!(Country::FR.iso_code(), "FR");
    /// ```
    pub fn iso_code(self) -> &'static str {
        match self {
            {%- for country in countries %}
            Self::{{ country.iso_code }} => "{{ country.iso_code }}",
            {%- endfor %}
        }
    }
}

impl Display for Country {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.name())
    }
}

impl FromStr for Country {
    type Err = UnknownCountryCode;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s {
            {%- for country in countries %}
            "{{ country.iso_code }}" => Ok(Self::{{ country.iso_code }}),
            {%- endfor %}
            _ => Err(UnknownCountryCode(s.to_string())),
        }
    }
}

