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

import UIKit

class AudioSettingsMeloDIntroViewModel: AudioSettingsBaseViewModel {
    enum RowType: String, CaseIterable, AudioSettingRowSource {
        case bassManagement = "Bass Management"
        case aroundPro = "Around Pro"
        case matrix = "Matrix"
        case drc = "DRC"
        case tone = "BTL Tone Control"
        case geq = "Graphic Equalizer"
        case xoverFilter = "X-Over Filter"
        case limiter = "Multiband Limiter"
        case voicePlus = "Voice+"
        case bassPlus = "Bass+"
        case peq = "Parametric Equalizer"

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

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

        func accessibilityTitle(player: IoTPlayer) -> String {
            return self.title()
        }

        func value(player: IoTPlayer) -> AudioSettingRowSourceResult {
            return .none
        }

        func viewModel(player: IoTPlayer)->AudioSettingsViewModel? {
            switch self {
            case .bassManagement:
                return AudioSettingsMeloDBassManagementViewModel()
            case .aroundPro:
                return AudioSettingsMeloDAroundProViewModel()
            case .matrix:
                return AudioSettingsMeloDMatrixViewModel()
            case .drc:
                return AudioSettingsMeloDDRCViewModel()
            case .tone:
                return AudioSettingsMeloDBTLToneViewModel()
            case .geq:
                return AudioSettingsMeloDGEQViewModel()
            case .xoverFilter:
                return AudioSettingsMeloDXOverFilterViewModel()
            case .limiter:
                return AudioSettingsMeloDMultibandLimiterViewModel()
            case .voicePlus:
                return AudioSettingsMeloDVoicePlusViewModel()
            case .bassPlus:
                return AudioSettingsMeloDBassPlusViewModel()
            case .peq:
                return AudioSettingsMeloDPEQViewModel()
            }
        }

        func available(player: IoTPlayer) -> Bool {
            switch self {
            case .bassManagement:
                return player.meloDBassManagementSupported
            case .aroundPro:
                return player.meloDAroundProSupported
            case .matrix:
                return player.meloDMatrixSupported
            case .drc:
                return player.meloDDRCSupported
            case .tone:
                return player.meloDBtlToneCtrlSupported
            case .geq:
                return player.meloDGEQSupported
            case .xoverFilter:
                return player.meloDCoppXOverFilterSupported
            case .limiter:
                return player.meloDCoppMultiBandLimiterSupported
            case .voicePlus:
                return player.meloDCoppVoicePlusSupported
            case .bassPlus:
                return player.meloDCoppBassPlusSupported
            case .peq:
                return player.meloDCoppPEQSupported
            }
        }
    }

    override var title: String { return NSLocalizedString("MeloD", comment: "MeloD") }

    override func rows()->[AudioSettingsRow] {
        let allCases = RowType.allCases
        if
            let playerID = playerID,
            let player = playerController?.player(id: playerID) {
            let rows = allCases.compactMap { (rowType) -> AudioSettingsRow? in
                if rowType.available(player: player) {
                    return AudioSettingsRow(identifier: rowType.identifier(),
                                            type: AudioSettingsRowType.submenu,
                                            title: rowType.title(),
                                            accessibilityTitle: rowType.accessibilityTitle(player: player))
                } else {
                    return AudioSettingsRow(identifier: rowType.identifier(),
                                            type: AudioSettingsRowType.simple,
                                            title: rowType.title() + " " + NSLocalizedString("(Unavailable)", comment: "Unavailable"),
                                            accessibilityTitle: rowType.accessibilityTitle(player: player))
                }
            }
            return rows
        } else {
            return []
        }
    }

    override func submenuTapped(_ row: AudioSettingsRow) {
        submenuTapped(row, rowEnum: RowType.self)
    }
}
