import Foundation

/// Built-in EQ presets with predefined gain values for 3-band EQ.
/// "Custom" is auto-assigned when slider values don't match any named preset.
enum EQPreset: String, CaseIterable, Identifiable {
    case flat
    case bassBoost
    case bassCut
    case loudness
    case vocalFocus
    case custom

    var id: String { rawValue }

    /// Human-readable label for the preset picker.
    var displayName: String {
        switch self {
        case .flat: "Flat"
        case .bassBoost: "Bass Boost"
        case .bassCut: "Bass Cut"
        case .loudness: "Loudness"
        case .vocalFocus: "Vocal Focus"
        case .custom: "Custom"
        }
    }

    /// Gain values (low, mid, high) for each named preset.
    /// Returns nil for `.custom` since it has no fixed values.
    var gains: (low: Float, mid: Float, high: Float)? {
        switch self {
        case .flat:       (0, 0, 0)
        case .bassBoost:  (6, 0, 0)
        case .bassCut:    (-24, 0, 0)
        case .loudness:   (4, -2, 4)
        case .vocalFocus: (-4, 4, -2)
        case .custom:     nil
        }
    }

    /// Auto-detect which preset matches the given gain values,
    /// or return `.custom` if no match.
    static func detect(low: Float, mid: Float, high: Float) -> EQPreset {
        for preset in Self.allCases where preset != .custom {
            guard let gains = preset.gains else { continue }
            if gains.low == low && gains.mid == mid && gains.high == high {
                return preset
            }
        }
        return .custom
    }
}
