//
//  OrderTrackerModel.swift
//  MVMCoreUI
//
//  Created by Kevin Christiano on 7/1/20.
//  Copyright © 2020 Verizon Wireless. All rights reserved.
//

import UIKit
import MVMCoreUI

open class OrderTrackerModel: MoleculeModelProtocol {
    //--------------------------------------------------
    // MARK: - Properties
    //--------------------------------------------------
    @DecodableDefault.UUIDString public var id: String

    public var backgroundColor: Color?
    
    public static var identifier: String = "orderTracker"
    public var steps: [StepModel]
    
    //--------------------------------------------------
    // MARK: - Keys
    //--------------------------------------------------
    
    private enum CodingKeys: String, CodingKey {
        case id
        case moleculeName
        case backgroundColor
        case steps
    }
    
    //--------------------------------------------------
    // MARK: - Codec
    //--------------------------------------------------
    
    required public init(from decoder: Decoder) throws {
        let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
        backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
        steps = try typeContainer.decode([StepModel].self, forKey: .steps)
    }
    
    public func encode(to encoder: Encoder) throws {
        var container = encoder.container(keyedBy: CodingKeys.self)
        try container.encode(moleculeName, forKey: .moleculeName)
        try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
        try container.encode(steps, forKey: .steps)
    }
}
