// <FILE>crates/mcu-scheme/src/scheme_tonal_spot.rs</FILE> - <DESC>Tonal spot color scheme</DESC>
// <VERS>VERSION: 2.0.0</VERS>
// <WCTX>Full implementation of tonal spot scheme wrapper</WCTX>
// <CLOG>Implement SchemeTonalSpot wrapping DynamicScheme with Variant::TonalSpot</CLOG>

use mcu_dynamiccolor::{DynamicScheme, DynamicSchemeOptions, Platform, SpecVersion, Variant};
use mcu_hct::Hct;
use std::ops::Deref;

/// A tonal spot color scheme emphasizing the source color with tonal adjustments.
///
/// Uses the source color as an accent with complementary tones.
/// This is the most commonly used variant and the default for Material Design 3.
///
/// # Example
///
/// ```
/// use mcu_scheme::SchemeTonalSpot;
/// use mcu_hct::Hct;
///
/// let source = Hct::from_int(0xFF0000FF); // Blue
/// let scheme = SchemeTonalSpot::new(source, false, 0.0);
/// assert!(!scheme.is_dark);
/// ```
pub struct SchemeTonalSpot {
    scheme: DynamicScheme,
}

impl SchemeTonalSpot {
    /// Create a new tonal spot scheme.
    ///
    /// # Arguments
    ///
    /// * `source_color_hct` - The source color in HCT color space
    /// * `is_dark` - Whether to generate a dark mode scheme
    /// * `contrast_level` - Contrast level from -1.0 (minimum) to 1.0 (maximum), 0.0 is standard
    pub fn new(source_color_hct: Hct, is_dark: bool, contrast_level: f64) -> Self {
        let scheme = DynamicScheme::new(DynamicSchemeOptions::new(
            source_color_hct,
            Variant::TonalSpot,
            contrast_level,
            is_dark,
        ));
        Self { scheme }
    }

    /// Create a new tonal spot scheme with full options.
    ///
    /// # Arguments
    ///
    /// * `source_color_hct` - The source color in HCT color space
    /// * `is_dark` - Whether to generate a dark mode scheme
    /// * `contrast_level` - Contrast level from -1.0 (minimum) to 1.0 (maximum), 0.0 is standard
    /// * `platform` - Target platform (Phone or Watch)
    /// * `spec_version` - Design spec version (2021 or 2025)
    pub fn with_options(
        source_color_hct: Hct,
        is_dark: bool,
        contrast_level: f64,
        platform: Platform,
        spec_version: SpecVersion,
    ) -> Self {
        let mut options = DynamicSchemeOptions::new(
            source_color_hct,
            Variant::TonalSpot,
            contrast_level,
            is_dark,
        );
        options.platform = Some(platform);
        options.spec_version = Some(spec_version);
        Self {
            scheme: DynamicScheme::new(options),
        }
    }
}

impl Deref for SchemeTonalSpot {
    type Target = DynamicScheme;

    fn deref(&self) -> &Self::Target {
        &self.scheme
    }
}

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

    #[test]
    fn test_new_light_mode() {
        let source = Hct::from_int(0xFF0000FF);
        let scheme = SchemeTonalSpot::new(source, false, 0.0);

        assert_eq!(scheme.variant, Variant::TonalSpot);
        assert!(!scheme.is_dark);
        assert_eq!(scheme.contrast_level, 0.0);
    }

    #[test]
    fn test_new_dark_mode() {
        let source = Hct::from_int(0xFF0000FF);
        let scheme = SchemeTonalSpot::new(source, true, 0.0);

        assert_eq!(scheme.variant, Variant::TonalSpot);
        assert!(scheme.is_dark);
    }

    #[test]
    fn test_contrast_levels() {
        let source = Hct::from_int(0xFF0000FF);

        let low = SchemeTonalSpot::new(source, false, -1.0);
        assert_eq!(low.contrast_level, -1.0);

        let high = SchemeTonalSpot::new(source, false, 1.0);
        assert_eq!(high.contrast_level, 1.0);
    }

    #[test]
    fn test_with_options() {
        let source = Hct::from_int(0xFF0000FF);
        let scheme = SchemeTonalSpot::with_options(
            source,
            true,
            0.5,
            Platform::Watch,
            SpecVersion::Spec2025,
        );

        assert_eq!(scheme.variant, Variant::TonalSpot);
        assert!(scheme.is_dark);
        assert_eq!(scheme.contrast_level, 0.5);
        assert_eq!(scheme.platform, Platform::Watch);
        assert_eq!(scheme.spec_version, SpecVersion::Spec2025);
    }

    #[test]
    fn test_deref_access() {
        let source = Hct::from_int(0xFF0000FF);
        let scheme = SchemeTonalSpot::new(source, false, 0.0);

        // Access DynamicScheme fields through Deref
        let _primary = &scheme.primary_palette;
        let _secondary = &scheme.secondary_palette;
        let _argb = scheme.source_color_argb;
    }
}

// <FILE>crates/mcu-scheme/src/scheme_tonal_spot.rs</FILE> - <DESC>Tonal spot color scheme</DESC>
// <VERS>END OF VERSION: 2.0.0</VERS>
