//! Configuration tier definitions.

/// Configuration tier represents the priority level of a configuration source.
///
/// Tiers are ordered by priority: User > Local > System.
/// When merging configurations, User tier overrides Local,
/// and Local overrides System.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
pub enum ConfigTier {
    /// User-specific configuration.
    /// Highest priority, typically in user's home directory.
    /// Examples: `~/.config/app/`, `~/.apprc`
    #[default]
    User = 3,

    /// Local/machine-specific configuration.
    /// Medium priority, typically in `/usr/local/etc` or similar.
    /// Examples: `/usr/local/etc/app/`, `/opt/app/etc/`
    Local = 2,

    /// System-wide configuration.
    /// Lowest priority, typically in `/etc/`.
    /// Examples: `/etc/app/`, `/etc/xdg/app/`
    System = 1,
}

impl ConfigTier {
    /// Returns the priority level as a number.
    /// Higher values mean higher priority.
    #[must_use]
    pub const fn priority(self) -> u8 {
        match self {
            Self::User => 3,
            Self::Local => 2,
            Self::System => 1,
        }
    }

    /// Returns true if this tier is user-level.
    #[must_use]
    pub const fn is_user(self) -> bool {
        matches!(self, Self::User)
    }

    /// Returns true if this tier is local-level.
    #[must_use]
    pub const fn is_local(self) -> bool {
        matches!(self, Self::Local)
    }

    /// Returns true if this tier is system-level.
    #[must_use]
    pub const fn is_system(self) -> bool {
        matches!(self, Self::System)
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_tier_ordering() {
        assert!(ConfigTier::User > ConfigTier::Local);
        assert!(ConfigTier::Local > ConfigTier::System);
        assert!(ConfigTier::User > ConfigTier::System);
    }

    #[test]
    fn test_priority_values() {
        assert_eq!(ConfigTier::User.priority(), 3);
        assert_eq!(ConfigTier::Local.priority(), 2);
        assert_eq!(ConfigTier::System.priority(), 1);
    }
}
