//! Platform configuration — parsed from `el.toml`.

/// Which platform to target for rendering.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum PlatformTarget {
    /// Web: DOM rendering in browsers.
    Web,
    /// Server: SSR — render to HTML string, served by axum.
    Server,
    /// iOS: UIKit via C FFI / ObjC bridge.
    Ios,
    /// Android: NDK + JNI bridge.
    Android,
    /// macOS: AppKit bindings.
    Macos,
    /// Linux: GTK/Wayland.
    Linux,
    /// Windows: Win32/WinUI.
    Windows,
}

impl PlatformTarget {
    /// Parse from the string value used in `el.toml`.
    pub fn from_str(s: &str) -> Option<Self> {
        match s.to_lowercase().as_str() {
            "web" => Some(Self::Web),
            "server" => Some(Self::Server),
            "ios" => Some(Self::Ios),
            "android" => Some(Self::Android),
            "macos" => Some(Self::Macos),
            "linux" => Some(Self::Linux),
            "windows" => Some(Self::Windows),
            _ => None,
        }
    }

    /// The canonical string name for this target.
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::Web => "web",
            Self::Server => "server",
            Self::Ios => "ios",
            Self::Android => "android",
            Self::Macos => "macos",
            Self::Linux => "linux",
            Self::Windows => "windows",
        }
    }

    /// Whether this target is a native (non-web, non-server) platform.
    pub fn is_native(&self) -> bool {
        matches!(self, Self::Ios | Self::Android | Self::Macos | Self::Linux | Self::Windows)
    }
}

/// Full platform configuration, reflecting the `[platform]` section of `el.toml`.
#[derive(Debug, Clone)]
pub struct PlatformConfig {
    pub target: PlatformTarget,
    /// Enable server-side rendering fallback.
    pub ssr: bool,
}

impl Default for PlatformConfig {
    fn default() -> Self {
        Self {
            target: PlatformTarget::Web,
            ssr: false,
        }
    }
}

impl PlatformConfig {
    pub fn new(target: PlatformTarget) -> Self {
        Self { target, ssr: false }
    }

    pub fn with_ssr(mut self, ssr: bool) -> Self {
        self.ssr = ssr;
        self
    }
}
