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


open class LabelAttributeActionModel: LabelAttributeModel {
    //--------------------------------------------------
    // MARK: - Properties
    //--------------------------------------------------
    
    override public class var identifier: String { "action" }
    
    var action: ActionModelProtocol
    
    //--------------------------------------------------
    // MARK: - Initializer
    //--------------------------------------------------
    
    public init(_ location: Int, _ length: Int, action: ActionModelProtocol) {
        self.action = action
        super.init(location, length)
    }
    
    //--------------------------------------------------
    // MARK: - Keys
    //--------------------------------------------------
    
    private enum CodingKeys: String, CodingKey {
        case action
    }
    
    //--------------------------------------------------
    // MARK: - Codec
    //--------------------------------------------------
    
    required public init(from decoder: Decoder) throws {
        let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
        action = try typeContainer.decodeModel(codingKey: .action)
        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.encodeModel(action, forKey: .action)
    }
}
