//
//  ChipDenomination.swift
//  CasinoKit
//
//  The available chip denominations with their properties.
//

import SwiftUI

/// The available chip denominations for casino games.
/// Colors follow standard US casino chip conventions.
public enum ChipDenomination: Int, CaseIterable, Identifiable, Sendable {
    case one = 1              // White/Blue/Gray
    case five = 5             // Red
    case twentyFive = 25      // Green
    case hundred = 100        // Black
    case fiveHundred = 500    // Purple
    case thousand = 1_000     // Yellow
    case fiveThousand = 5_000 // Brown/Orange
    case tenThousand = 10_000 // Custom (often plaques)
    case twentyFiveThousand = 25_000    // Plaque style
    case hundredThousand = 100_000      // Plaque style
    
    public var id: Int { rawValue }
    
    /// The display text for this denomination.
    public var displayText: String {
        switch self {
        case .one: return "1"
        case .five: return "5"
        case .twentyFive: return "25"
        case .hundred: return "100"
        case .fiveHundred: return "500"
        case .thousand: return "1K"
        case .fiveThousand: return "5K"
        case .tenThousand: return "10K"
        case .twentyFiveThousand: return "25K"
        case .hundredThousand: return "100K"
        }
    }
    
    /// The minimum balance required to show this chip in the selector.
    /// Higher chips unlock as you win more!
    public var unlockBalance: Int {
        switch self {
        case .one, .five, .twentyFive, .hundred: return 0 // Always available
        case .fiveHundred: return 500
        case .thousand: return 1_000
        case .fiveThousand: return 5_000
        case .tenThousand: return 10_000
        case .twentyFiveThousand: return 25_000
        case .hundredThousand: return 100_000
        }
    }
    
    /// Whether this chip should be shown based on the player's balance.
    public func isUnlocked(forBalance balance: Int) -> Bool {
        balance >= unlockBalance
    }
    
    /// Returns chips that should be visible for a given balance.
    public static func availableChips(forBalance balance: Int) -> [ChipDenomination] {
        allCases.filter { $0.isUnlocked(forBalance: balance) }
    }
    
    /// Accessibility label for VoiceOver.
    public var accessibilityLabel: String {
        String(localized: "\(rawValue) dollar chip", bundle: .module)
    }
}

