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


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