//
//  CasinoTheme.swift
//  CasinoKit
//
//  Protocol defining customizable theme for casino games.
//

import SwiftUI

/// A protocol defining the visual theme for casino game components.
///
/// Conform to this protocol to create custom themes for your casino games.
/// Use `DefaultCasinoTheme` for a ready-to-use classic casino look.
public protocol CasinoTheme: Sendable {
    
    // MARK: - Table Colors
    
    /// The primary table felt color.
    var tableFeltColor: Color { get }
    
    /// A lighter variant of the table felt for gradients.
    var tableFeltLightColor: Color { get }
    
    /// A darker variant of the table felt for gradients.
    var tableFeltDarkColor: Color { get }
    
    // MARK: - Accent Colors
    
    /// The primary accent color (typically gold for casino themes).
    var accentColor: Color { get }
    
    /// A lighter variant of the accent color.
    var accentLightColor: Color { get }
    
    /// A darker variant of the accent color.
    var accentDarkColor: Color { get }
    
    // MARK: - Card Colors
    
    /// The background color for card fronts.
    var cardFrontColor: Color { get }
    
    /// The primary color for card backs.
    var cardBackPrimaryColor: Color { get }
    
    /// The secondary color for card backs.
    var cardBackSecondaryColor: Color { get }
    
    // MARK: - Chip Colors
    
    /// Returns the color set for a given chip denomination.
    func chipColors(for denomination: ChipDenomination) -> ChipColorSet
}

/// A set of colors defining a chip's appearance.
public struct ChipColorSet: Sendable {
    /// The main color of the chip.
    public let primary: Color
    
    /// The highlight/secondary color of the chip.
    public let secondary: Color
    
    /// The edge stripe color.
    public let stripe: Color
    
    public init(primary: Color, secondary: Color, stripe: Color) {
        self.primary = primary
        self.secondary = secondary
        self.stripe = stripe
    }
}

/// The default casino theme with classic green felt and gold accents.
public struct DefaultCasinoTheme: CasinoTheme {
    
    public init() {}
    
    // MARK: - Table Colors
    
    public var tableFeltColor: Color {
        Color(red: 0.05, green: 0.35, blue: 0.15)
    }
    
    public var tableFeltLightColor: Color {
        Color(red: 0.08, green: 0.45, blue: 0.2)
    }
    
    public var tableFeltDarkColor: Color {
        Color(red: 0.03, green: 0.25, blue: 0.1)
    }
    
    // MARK: - Accent Colors
    
    public var accentColor: Color {
        Color(red: 0.85, green: 0.65, blue: 0.2)
    }
    
    public var accentLightColor: Color {
        Color(red: 1.0, green: 0.85, blue: 0.4)
    }
    
    public var accentDarkColor: Color {
        Color(red: 0.7, green: 0.5, blue: 0.15)
    }
    
    // MARK: - Card Colors
    
    public var cardFrontColor: Color {
        Color(white: 0.96)
    }
    
    public var cardBackPrimaryColor: Color {
        Color(red: 0.6, green: 0.1, blue: 0.15)
    }
    
    public var cardBackSecondaryColor: Color {
        Color(red: 0.75, green: 0.15, blue: 0.2)
    }
    
    // MARK: - Chip Colors
    
    public func chipColors(for denomination: ChipDenomination) -> ChipColorSet {
        switch denomination {
        // $1 - White/Light Blue (classic casino white chip)
        case .one:
            return ChipColorSet(
                primary: Color(red: 0.92, green: 0.94, blue: 0.96),
                secondary: Color(red: 0.98, green: 0.99, blue: 1.0),
                stripe: Color(red: 0.3, green: 0.5, blue: 0.7) // Blue accent
            )
        // $5 - Red (standard casino red)
        case .five:
            return ChipColorSet(
                primary: Color(red: 0.8, green: 0.15, blue: 0.15),
                secondary: Color(red: 0.95, green: 0.25, blue: 0.25),
                stripe: .white
            )
        // $25 - Green (standard casino green)
        case .twentyFive:
            return ChipColorSet(
                primary: Color(red: 0.1, green: 0.55, blue: 0.25),
                secondary: Color(red: 0.15, green: 0.7, blue: 0.35),
                stripe: .white
            )
        // $100 - Black (standard casino black)
        case .hundred:
            return ChipColorSet(
                primary: Color(red: 0.1, green: 0.1, blue: 0.12),
                secondary: Color(red: 0.2, green: 0.2, blue: 0.22),
                stripe: Color(red: 0.85, green: 0.65, blue: 0.2) // Gold accent
            )
        // $500 - Purple (standard casino purple)
        case .fiveHundred:
            return ChipColorSet(
                primary: Color(red: 0.45, green: 0.15, blue: 0.55),
                secondary: Color(red: 0.6, green: 0.25, blue: 0.7),
                stripe: .white
            )
        // $1,000 - Yellow/Gold (standard casino yellow)
        case .thousand:
            return ChipColorSet(
                primary: Color(red: 0.95, green: 0.8, blue: 0.2),
                secondary: Color(red: 1.0, green: 0.9, blue: 0.4),
                stripe: .black
            )
        // $5,000 - Brown/Orange (standard casino brown)
        case .fiveThousand:
            return ChipColorSet(
                primary: Color(red: 0.55, green: 0.35, blue: 0.2),
                secondary: Color(red: 0.7, green: 0.45, blue: 0.25),
                stripe: Color(red: 0.9, green: 0.7, blue: 0.3) // Gold accent
            )
        // $10,000+ - Custom/Gray (high roller, often plaque style)
        case .tenThousand:
            return ChipColorSet(
                primary: Color(red: 0.6, green: 0.65, blue: 0.7),
                secondary: Color(red: 0.75, green: 0.8, blue: 0.85),
                stripe: Color(red: 0.2, green: 0.25, blue: 0.4) // Dark blue accent
            )
        // $25,000 - Teal/Custom (often plaques at this level)
        case .twentyFiveThousand:
            return ChipColorSet(
                primary: Color(red: 0.15, green: 0.45, blue: 0.5),
                secondary: Color(red: 0.2, green: 0.6, blue: 0.65),
                stripe: Color(red: 0.9, green: 0.75, blue: 0.3) // Gold accent
            )
        // $100,000 - Burgundy/Custom (VIP plaques)
        case .hundredThousand:
            return ChipColorSet(
                primary: Color(red: 0.5, green: 0.1, blue: 0.15),
                secondary: Color(red: 0.65, green: 0.15, blue: 0.2),
                stripe: Color(red: 0.95, green: 0.8, blue: 0.35) // Bright gold
            )
        }
    }
}

