//
//  ListThreeColumnSpeedTestModel.swift
//  MVMCoreUI
//
//  Created by Lekshmi S on 04/08/20.
//  Copyright © 2020 Verizon Wireless. All rights reserved.
//


public class ListThreeColumnSpeedTestModel: ListItemModel, MoleculeModelProtocol {
    //--------------------------------------------------
    // MARK: - Properties
    //--------------------------------------------------
    
    public static var identifier: String = "list3CSpdTst"
    public var title: LabelModel
    public var topLeftHeadlineBody: HeadlineBodyModel
    public var topCenterHeadlineBody: HeadlineBodyModel
    public var topRightHeadlineBody: HeadlineBodyModel
    public var bottomLeftHeadlineBody: HeadlineBodyModel
    public var bottomCenterHeadlineBody: HeadlineBodyModel
    public var bottomRightHeadlineBody: HeadlineBodyModel
    
    //--------------------------------------------------
    // MARK: - Initializer
    //--------------------------------------------------
    
    public init(title: LabelModel, topLeftHeadlineBody: HeadlineBodyModel, topCenterHeadlineBody: HeadlineBodyModel, topRightHeadlineBody: HeadlineBodyModel, bottomLeftHeadlineBody: HeadlineBodyModel, bottomCenterHeadlineBody: HeadlineBodyModel, bottomRightHeadlineBody: HeadlineBodyModel) {
        self.title = title
        self.topLeftHeadlineBody = topLeftHeadlineBody
        self.topCenterHeadlineBody = topCenterHeadlineBody
        self.topRightHeadlineBody = topRightHeadlineBody
        self.bottomLeftHeadlineBody = bottomLeftHeadlineBody
        self.bottomCenterHeadlineBody = bottomCenterHeadlineBody
        self.bottomRightHeadlineBody = bottomRightHeadlineBody
        super.init()
    }
    
    //------------------------------------------------------
    // MARK: - Method
    //------------------------------------------------------
    
    override public func setDefaults() {
        styleHeadlineBody(topLeftHeadlineBody, true)
        styleHeadlineBody(bottomLeftHeadlineBody, false)
        styleHeadlineBody(topCenterHeadlineBody, false)
        styleHeadlineBody(bottomCenterHeadlineBody, false)
        styleHeadlineBody(topRightHeadlineBody, false)
        styleHeadlineBody(bottomRightHeadlineBody, false)
        super.setDefaults()
    }
    
    //Method to style headline and body of HeadlineBody
    func styleHeadlineBody(_ headlineBodyModel: HeadlineBodyModel, _ isBodyMicro: Bool) {
        
        headlineBodyModel.headline?.fontStyle = .RegularMicro
        headlineBodyModel.headline?.textColor = Color(uiColor: .mvmCoolGray6)
        
        if isBodyMicro {
            headlineBodyModel.body?.fontStyle = .RegularMicro
            headlineBodyModel.body?.textColor = Color(uiColor: .mvmCoolGray6)
        } else {
            headlineBodyModel.body?.fontStyle = .RegularBodySmall
        }
    }
    
    //--------------------------------------------------
    // MARK: - Keys
    //--------------------------------------------------
    
    private enum CodingKeys: String, CodingKey {
        case moleculeName
        case title
        case topLeftHeadlineBody
        case topCenterHeadlineBody
        case topRightHeadlineBody
        case bottomLeftHeadlineBody
        case bottomCenterHeadlineBody
        case bottomRightHeadlineBody
    }
    
    //--------------------------------------------------
    // MARK: - Codec
    //--------------------------------------------------
    
    required public init(from decoder: Decoder) throws {
        let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
        title = try typeContainer.decode(LabelModel.self, forKey: .title)
        topLeftHeadlineBody = try typeContainer.decode(HeadlineBodyModel.self, forKey: .topLeftHeadlineBody)
        topCenterHeadlineBody = try typeContainer.decode(HeadlineBodyModel.self, forKey: .topCenterHeadlineBody)
        topRightHeadlineBody = try typeContainer.decode(HeadlineBodyModel.self, forKey: .topRightHeadlineBody)
        bottomLeftHeadlineBody = try typeContainer.decode(HeadlineBodyModel.self, forKey: .bottomLeftHeadlineBody)
        bottomCenterHeadlineBody = try typeContainer.decode(HeadlineBodyModel.self, forKey: .bottomCenterHeadlineBody)
        bottomRightHeadlineBody = try typeContainer.decode(HeadlineBodyModel.self, forKey: .bottomRightHeadlineBody)
        try super.init(from: decoder)
    }
    
    public override func encode(to encoder: Encoder) throws {
        try super.encode(to: encoder)
        var container = encoder.container(keyedBy: CodingKeys.self)
        try container.encode(moleculeName, forKey: .moleculeName)
        try container.encode(title, forKey: .title)
        try container.encode(topLeftHeadlineBody, forKey: .topLeftHeadlineBody)
        try container.encode(topCenterHeadlineBody, forKey: .topCenterHeadlineBody)
        try container.encode(topRightHeadlineBody, forKey: .topRightHeadlineBody)
        try container.encode(bottomLeftHeadlineBody, forKey: .bottomLeftHeadlineBody)
        try container.encode(bottomCenterHeadlineBody, forKey: .bottomCenterHeadlineBody)
        try container.encode(bottomRightHeadlineBody, forKey: .bottomRightHeadlineBody)
    }
}
