//
//  © 2019-2020 Qualcomm Technologies, Inc. and/or its subsidiaries. All rights reserved.
//

import UIKit

class AudioSettingsTrumpetPresetsViewModel: AudioSettingsBaseViewModel {
    enum Preset: String, CaseIterable, AudioSettingRowSource {
    	case off = "Off"
        case dynamic = "Dynamic"
        case movie = "Movie"
        case music = "Music"
        case game = "Game"
        case voice = "Voice"
        func identifier() -> String {
            return self.rawValue
        }

        func title() -> String {
            return NSLocalizedString(self.rawValue, comment: "Trumpet Preset")
        }

        func accessibilityTitle(player: IoTPlayer) -> String {
            return NSLocalizedString(self.rawValue, comment: "Trumpet Preset")
        }

        func viewModel(player: IoTPlayer) -> AudioSettingsViewModel? {
            return nil
        }

        func available(player: IoTPlayer) -> Bool {
            return true
        }

        func value(player: IoTPlayer) -> AudioSettingRowSourceResult {
            let index = min(player.currentTrumpetPreset.rawValue, Preset.allCases.count)
            let option = Preset.allCases[index]
            return .checked(value: self == option)
        }
    }

    override var title: String { return NSLocalizedString("TRUMPET PRESET", comment: "Trumpet Preset") }

    override func rows()->[AudioSettingsRow] {
        return rows(rowEnum: Preset.self)
    }

    override func checkableOptionChecked(_ row: AudioSettingsRow) {
        guard
            let playerID = playerID,
            let player = playerController?.player(id: playerID),
            let index = Preset.allCases.firstIndex(where: { (mode) -> Bool in
                return mode.identifier() == row.identifier
            })
            else {
                return
        }

        if let preset = IoTPreset(rawValue: index) {
            player.setCurrentTrumpetPreset(preset ,
                                           completion: nil,
                                           completionQueue: nil)
        }
    }
}
