//
//  HeadersH2PricingTwoRowsModel.swift
//  MVMCoreUI
//
//  Created by Lekshmi S on 16/06/20.
//  Copyright © 2020 Verizon Wireless. All rights reserved.
//

import Foundation

public class HeadersH2PricingTwoRowsModel: HeaderModel, MoleculeModelProtocol {
    //--------------------------------------------------
    // MARK: - Properties
    //--------------------------------------------------
    public static var identifier: String = "headerH2TwoRows"
    public var headline: LabelModel
    public var body: LabelModel
    public var subBody: LabelModel?
    public var body2: LabelModel
    public var subBody2: LabelModel?
    public var body3: LabelModel
    public var subBody3: LabelModel?
    
    //--------------------------------------------------
    // MARK: - Initializer
    //--------------------------------------------------
    public init(headline: LabelModel, body: LabelModel, subBody: LabelModel? = nil, body2: LabelModel, subBody2: LabelModel? = nil, body3: LabelModel, subBody3: LabelModel? = nil) {
        self.headline = headline
        self.body = body
        self.subBody = subBody
        self.body2 = body2
        self.subBody2 = subBody2
        self.body3 = body3
        self.subBody3 = subBody3
        super.init()
    }
    
    //--------------------------------------------------
    // MARK: - Methods
    //--------------------------------------------------
    public override func setDefaults() {
        if topPadding == nil {
            topPadding = Padding.Component.VerticalMarginSpacing
        }
        if bottomPadding == nil {
            bottomPadding = Padding.Component.VerticalMarginSpacing
        }
        super.setDefaults()
        subBody?.attributes = [LabelAttributeStrikeThroughModel(0, subBody?.text.count ?? 0)]
        subBody2?.attributes = [LabelAttributeStrikeThroughModel(0, subBody2?.text.count ?? 0)]
        subBody3?.attributes = [LabelAttributeStrikeThroughModel(0, subBody3?.text.count ?? 0)]
        if body.numberOfLines == nil {
            body.numberOfLines = 1
        }
        if body2.numberOfLines == nil {
            body2.numberOfLines = 1
        }
        if body3.numberOfLines == nil {
            body3.numberOfLines = 1
        }
    }
    
    //--------------------------------------------------
    // MARK: - Keys
    //--------------------------------------------------
    private enum CodingKeys: String, CodingKey {
        case moleculeName
        case headline
        case body
        case subBody
        case body2
        case subBody2
        case body3
        case subBody3
    }
    
    //--------------------------------------------------
    // MARK: - Codec
    //--------------------------------------------------
    required public init(from decoder: Decoder) throws {
        let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
        headline = try typeContainer.decode(LabelModel.self, forKey: .headline)
        body = try typeContainer.decode(LabelModel.self, forKey: .body)
        subBody = try typeContainer.decodeIfPresent(LabelModel.self, forKey: .subBody)
        body2 = try typeContainer.decode(LabelModel.self, forKey: .body2)
        subBody2 = try typeContainer.decodeIfPresent(LabelModel.self, forKey: .subBody2)
        body3 = try typeContainer.decode(LabelModel.self, forKey: .body3)
        subBody3 = try typeContainer.decodeIfPresent(LabelModel.self, forKey: .subBody3)
        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(headline, forKey: .headline)
        try container.encode(body, forKey: .body)
        try container.encodeIfPresent(subBody, forKey: .subBody)
        try container.encode(body2, forKey: .body2)
        try container.encodeIfPresent(subBody2, forKey: .subBody2)
        try container.encode(body3, forKey: .body3)
        try container.encodeIfPresent(subBody3, forKey: .subBody3)
    }
}
