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


@objcMembers open class LabelAttributeModel: ModelProtocol {
    //--------------------------------------------------
    // MARK: - Properties
    //--------------------------------------------------
    
    public static var categoryName: String { "\(LabelAttributeModel.self)" }
    
    public static var categoryCodingKey: String { "type" }
    
    public class var identifier: String { "" }
    
    var type: String {
        get { Self.identifier }
    }
    
    var location: Int
    var length: Int
    
    //--------------------------------------------------
    // MARK: - Initializer
    //--------------------------------------------------
    
    public init(_ location: Int, _ length: Int) {
        self.location = location
        self.length = length
    }
    
    //--------------------------------------------------
    // MARK: - Keys
    //--------------------------------------------------
    
    private enum CodingKeys: String, CodingKey {
        case type
        case location
        case length
    }
    
    //--------------------------------------------------
    // MARK: - Codec
    //--------------------------------------------------
    
    required public init(from decoder: Decoder) throws {
        let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
        location = try typeContainer.decode(Int.self, forKey: .location)
        length = try typeContainer.decode(Int.self, forKey: .length)
    }
    
    public func encode(to encoder: Encoder) throws {
        var container = encoder.container(keyedBy: CodingKeys.self)
        try container.encode(type, forKey: .type)
        try container.encode(location, forKey: .location)
        try container.encode(length, forKey: .length)
    }
}
