//! Platform-specific directory discovery.

use crate::env::Env;
use std::path::PathBuf;

// Platform-specific implementations - conditionally compiled
#[cfg(all(target_os = "macos", feature = "macos-gui"))]
mod macos_gui;
#[cfg(all(target_os = "macos", feature = "macos-gui"))]
pub use macos_gui::MacOSGuiDirectoryFinder;

#[cfg(windows)]
mod windows;
#[cfg(windows)]
pub use windows::WindowsDirectoryFinder;

// Unix is used for Unix/Linux and macOS CLI (without macos-gui feature)
#[cfg(any(unix, not(feature = "macos-gui")))]
mod unix;
#[cfg(any(unix, not(feature = "macos-gui")))]
pub use unix::UnixDirectoryFinder;

/// Trait for finding configuration directories on a specific platform.
///
/// Implementations follow platform conventions:
/// - Unix/Linux: XDG Base Directory Specification
/// - Windows: Known Folder IDs
/// - macOS GUI: Application Support directories
pub trait DirectoryFinder: Send + Sync {
    /// Get user-specific configuration directories (highest priority).
    ///
    /// These directories are in the user's home and are writable.
    fn user_dirs(&self, env: &dyn Env) -> Vec<PathBuf>;

    /// Get local/machine-specific configuration directories (medium priority).
    ///
    /// These directories are machine-specific but may be writable.
    fn local_dirs(&self, env: &dyn Env) -> Vec<PathBuf>;

    /// Get system-wide configuration directories (lowest priority).
    ///
    /// These directories are typically read-only for regular users.
    fn system_dirs(&self, env: &dyn Env) -> Vec<PathBuf>;
}

/// Information about a configuration directory.
#[derive(Debug, Clone)]
pub struct DirectoryInfo {
    /// Path to the directory.
    pub path: PathBuf,
    /// Configuration tier (determines priority during merge).
    pub tier: crate::ConfigTier,
    /// Whether the directory exists.
    pub exists: bool,
}
