//
//  SoundCategory.swift
//  TheNoiseClock
//
//  Created by Matt Bruce on 9/8/25.
//

import Foundation

/// Enum representing sound categories with associated icons, display names, and metadata
public enum SoundCategory: String, CaseIterable, Identifiable {
    case all = "all"
    case colored = "colored"
    case ambient = "ambient"
    case nature = "nature"
    case mechanical = "mechanical"
    case alarm = "alarm"
    
    public var id: String { rawValue }
    
    /// Display name for the category
    public var displayName: String {
        switch self {
        case .all: return "All"
        case .colored: return "Colored"
        case .ambient: return "Ambient"
        case .nature: return "Nature"
        case .mechanical: return "Mechanical"
        case .alarm: return "Alarm Sounds"
        }
    }
    
    /// SF Symbol icon name for the category
    public var icon: String {
        switch self {
        case .all: return "speaker.wave.2"
        case .colored: return "waveform.path"
        case .ambient: return "waveform"
        case .nature: return "cloud.rain"
        case .mechanical: return "fan"
        case .alarm: return "alarm"
        }
    }
    
    /// Bundle name for organizing audio files
    public var bundleName: String? {
        switch self {
        case .all: return nil
        case .colored: return "Colored"
        case .ambient: return "Ambient"
        case .nature: return "Nature"
        case .mechanical: return "Mechanical"
        case .alarm: return nil
        }
    }
    
    /// Description of the category
    public var description: String {
        switch self {
        case .all: return "All available sounds"
        case .colored: return "Synthetic noise signals for focus, sleep, and relaxation"
        case .ambient: return "General ambient sounds"
        case .nature: return "Natural environmental sounds"
        case .mechanical: return "Mechanical and electronic sounds"
        case .alarm: return "Wake-up and notification alarm sounds"
        }
    }
    
    /// Preferred sort order for categories (lower number = appears first)
    public var sortOrder: Int {
        switch self {
        case .all: return 0
        case .colored: return 1
        case .ambient: return 2
        case .nature: return 3
        case .mechanical: return 4
        case .alarm: return 5
        }
    }
    
    /// Initialize from string, returning nil if invalid
    public init?(from string: String) {
        self.init(rawValue: string)
    }
    
    /// Get all non-alarm categories for noise selection
    public static var noiseCategories: [SoundCategory] {
        return [.all, .colored, .ambient, .nature, .mechanical]
    }
    
    /// Get all categories sorted by preferred order
    public static var sortedCategories: [SoundCategory] {
        return allCases.sorted { $0.sortOrder < $1.sortOrder }
    }
    
    /// Get noise categories sorted by preferred order
    public static var sortedNoiseCategories: [SoundCategory] {
        return noiseCategories.sorted { $0.sortOrder < $1.sortOrder }
    }
}
