//
//  LabelAttributeFontModel.swift
//  MVMCoreUI
//
//  Created by Ryan on 11/21/19.
//  Copyright © 2019 Verizon Wireless. All rights reserved.
//


@objcMembers public class LabelAttributeFontModel: LabelAttributeModel {
    //--------------------------------------------------
    // MARK: - Properties
    //--------------------------------------------------
    
    override public class var identifier: String { "font" }
    
    var style: Styler.Font?
    var name: String?
    var size: CGFloat?
    
    //--------------------------------------------------
    // MARK: - Keys
    //--------------------------------------------------
    
    private enum CodingKeys: String, CodingKey {
        case style
        case name
        case size
    }
    
    //--------------------------------------------------
    // MARK: - Codec
    //--------------------------------------------------
    
    required public init(from decoder: Decoder) throws {
        let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
        style = try typeContainer.decodeIfPresent(Styler.Font.self, forKey: .style)
        name = try typeContainer.decodeIfPresent(String.self, forKey: .name)
        size = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .size)
        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.encodeIfPresent(style, forKey: .style)
        try container.encodeIfPresent(name, forKey: .name)
        try container.encodeIfPresent(size, forKey: .size)
    }
}
