//
//  ListLeftVariableRadioButtonAndPaymentMethodModel.swift
//  MVMCoreUI
//
//  Created by Kruthika KP on 27/02/20.
//  Copyright © 2020 Verizon Wireless. All rights reserved.
//


public class ListLeftVariableRadioButtonAndPaymentMethodModel: ListItemModel, MoleculeModelProtocol {
    //--------------------------------------------------
    // MARK: - Properties
    //--------------------------------------------------
    
    public static var identifier: String = "listLVRBImg"
    public var radioButton: RadioButtonModel
    public var image: ImageViewModel
    public var eyebrowHeadlineBodyLink: EyebrowHeadlineBodyLinkModel
            
    //--------------------------------------------------
    // MARK: - Initializer
    //--------------------------------------------------
    
    public init(radioButton: RadioButtonModel, image: ImageViewModel, eyebrowHeadlineBodyLink:EyebrowHeadlineBodyLinkModel) {
        self.radioButton = radioButton
        self.image = image
        self.eyebrowHeadlineBodyLink = eyebrowHeadlineBodyLink
        super.init()
    }
    
    //--------------------------------------------------
    // MARK: - Methods
    //--------------------------------------------------
    
    public override func setDefaults() {
        super.setDefaults()
        if image.width == nil, image.height == nil {
            image.width = 32
            image.height = 32
        }
    }
    
    //--------------------------------------------------
    // MARK: - Keys
    //--------------------------------------------------
    
    private enum CodingKeys: String, CodingKey {
        case moleculeName
        case radioButton
        case image
        case eyebrowHeadlineBodyLink
    }
    
    //--------------------------------------------------
    // MARK: - Codec
    //--------------------------------------------------
    
    required public init(from decoder: Decoder) throws {
        let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
        radioButton = try typeContainer.decode(RadioButtonModel.self, forKey: .radioButton)
        image = try typeContainer.decode(ImageViewModel.self, forKey: .image)
        eyebrowHeadlineBodyLink = try typeContainer.decode(EyebrowHeadlineBodyLinkModel.self, forKey: .eyebrowHeadlineBodyLink)
        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(radioButton, forKey: .radioButton)
        try container.encode(image, forKey: .image)
        try container.encode(eyebrowHeadlineBodyLink, forKey: .eyebrowHeadlineBodyLink)
    }
}
