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

import UIKit

class AudioSettingsReverbPresetsViewModel: AudioSettingsBaseViewModel {
    override var title: String { return NSLocalizedString("PRESETS", comment: "Presets") }

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

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

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

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