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

import UIKit

class AudioSettingsMeloDXOverFilterViewModel: AudioSettingsBaseViewModel {
    private enum RowType: String, CaseIterable, AudioSettingRowSource {
        case enable = "enable"

        func identifier() -> String {
            return self.rawValue
        }

        func title() -> String {
            switch self {
            case .enable:
                return NSLocalizedString("Enabled", comment: "Enabled")
            }
        }

        func value(player: IoTPlayer) -> AudioSettingRowSourceResult {
            switch self {
            case .enable:
                return .bool(value: player.meloDCOPPXOverFilterEnabled)
            }
        }

        func accessibilityTitle(player: IoTPlayer) -> String {
            switch value(player: player) {
            case .bool(let value):
                if value {
                    return NSLocalizedString(Accessibility.AudioEffectsSettingsScreen.MeloD.XOverFilter.enabled, comment:"")
                } else {
                    return NSLocalizedString(Accessibility.AudioEffectsSettingsScreen.MeloD.XOverFilter.disabled, comment:"")
                }
            default:
                return ""
            }
        }

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

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

    override var title: String { return NSLocalizedString("X-OVER FILTER", comment: "X-Over Filter") }

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

    override func toggleChanged(_ row: AudioSettingsRow, value: Bool) {
        if
            let playerID = playerID,
            let player = playerController?.player(id: playerID) {
            startTimeoutTimer()
            player.setMeloDCOPPXOverFilterEnabled(value,
                                                  completion: nil,
                                                  completionQueue: nil)
        }
    }
}
