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

import Foundation

class SurroundChannelDisplayableWrapper: NSObject, MasterViewControllerDisplayable, MasterViewControllerDisplayablePlayerChild {
    weak var parent: MasterViewControllerDisplayable?
    let children = [MasterViewControllerDisplayable] ()
    let depth: UInt
    let playerID: String
    let channelPlayerID: String
    let channel: IoTHomeTheaterChannel
    var available: Bool
    var suppliedName: String
    var builtIn: Bool {
        return playerID == channelPlayerID
    }

    init(playerID: String,
         channelPlayerID: String,
         channel: IoTHomeTheaterChannel,
         depth: UInt,
         available: Bool,
         suppliedName: String) {
        self.playerID = playerID
        self.channelPlayerID = channelPlayerID
        self.depth = depth
        self.channel = channel
        self.available = available
        self.suppliedName = suppliedName

    }

    var id: String {
        return "CH:" + channelPlayerID + "-" + String(channel.rawValue)
    }

    var name: String {
        if suppliedName.count > 0 {
			return suppliedName
        }

        switch channel {
        case .none:
            return ""
        case .subwoofer:
            if builtIn {
				return NSLocalizedString("Built In Subwoofer", comment: "Subwoofer")
            } else {
            	return NSLocalizedString("Subwoofer", comment: "Subwoofer")
            }
        case .leftSurround:
            if builtIn {
                return NSLocalizedString("Built In Left Surround", comment: "Left Surround")
            } else {
                return NSLocalizedString("Left Surround", comment: "Left Surround")
            }
        case .rightSurround:
            if builtIn {
                return NSLocalizedString("Built In Right Surround", comment: "Right Surround")
            } else {
                return NSLocalizedString("Right Surround", comment: "Right Surround")
            }
        case .leftRearSurround:
            if builtIn {
                return NSLocalizedString("Built In Left Rear Surround", comment: "Left Rear Surround")
            } else {
                return NSLocalizedString("Left Rear Surround", comment: "Left Rear Surround")
            }
        case .rightRearSurround:
            if builtIn {
                return NSLocalizedString("Built In Right Rear Surround", comment: "Right Rear Surround")
            } else {
                return NSLocalizedString("Right Rear Surround", comment: "Right Rear Surround")
            }
        case .leftUpfiringSurround:
            if builtIn {
                return NSLocalizedString("Built In Left Upfiring Surround", comment: "Left Upfiring Surround")
            } else {
                return NSLocalizedString("Left Upfiring Surround", comment: "Left Upfiring Surround")
            }
        case .rightUpfiringSurround:
            if builtIn {
                return NSLocalizedString("Built In Right Upfiring Surround", comment: "Right Upfiring Surround")
            } else {
                return NSLocalizedString("Right Upfiring Surround", comment: "Right Upfiring Surround")
            }
        case .leftRearUpfiringSurround:
            if builtIn {
                return NSLocalizedString("Built In Left Rear Upfiring Surround", comment: "Left Rear Upfiring Surround")
            } else {
                return NSLocalizedString("Left Rear Upfiring Surround", comment: "Left Rear Upfiring Surround")
            }
        case .rightRearUpfiringSurround:
            if builtIn {
                return NSLocalizedString("Built In Right Rear Upfiring Surround", comment: "Right Rear Upfiring Surround")
            } else {
                return NSLocalizedString("Right Rear Upfiring Surround", comment: "Right Rear Upfiring Surround")
            }
        default:
            return "Unused speaker";
        }
    }

    var stateDescription: [String] {
        return []
    }

    var encapsulatedType: MasterViewControllerDisplayableType {
        return .speakerChannel
    }
}
