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

import UIKit

class AudioSettingsMeloDEQPresetViewModel: AudioSettingsBaseViewModel {
    override var title: String { return NSLocalizedString("EQ PRESET", comment: "Presets") }

    override func rows()->[AudioSettingsRow] {
        guard
            let playerID = playerID,
            let player = playerController?.player(id: playerID),
            player.meloDGEQSupported,
            player.meloDGEQEnabled else {
                return []
        }

        let presets = player.availableMeloDGEQPresets
        let rows = presets.map { (preset) -> AudioSettingsRow in
            return AudioSettingsRow(identifier: preset,
                                    type: .checkableOption(checked: preset == player.currentMeloDGEQPreset),
                                    title: preset,
                                    accessibilityTitle: preset)
        }
        return rows
    }

    override func checkableOptionChecked(_ row: AudioSettingsRow) {
        guard
            let playerID = playerID,
            let player = playerController?.player(id: playerID)
            else {
                return
        }

        player.setCurrentMeloDGEQPreset(row.identifier,
                                        completion: nil,
                                        completionQueue: nil)
    }
}
