//
//  BadgeModel.swift
//  MVMCoreUI
//
//  Created by Rebecca Antonelli on 4/6/23.
//  Copyright © 2023 Verizon Wireless. All rights reserved.
//

import Foundation
import VDS

open class BadgeModel: MoleculeModelProtocol {
    //--------------------------------------------------
    // MARK: - Properties
    //--------------------------------------------------
    public static var identifier: String = "badge"
    public var id: String = UUID().uuidString
    public var backgroundColor: Color?
    
    //--------------------------------------------------
    // MARK: - VDS Properties
    //--------------------------------------------------
    public var text: String = ""
    public var accessibilityText: String?
    public var maxWidth: CGFloat?
    public var numberOfLines: Int = 1
    public var fillColor = Badge.FillColor.red
    public var surface: Surface = .light
    
    private enum CodingKeys: String, CodingKey {
        case id, text, accessibilityText, fillColor, surface, numberOfLines, maxWidth
    }
        
    required public convenience init(from decoder: Decoder) throws {
        self.init()
        let container = try decoder.container(keyedBy: CodingKeys.self)
        id = try container.decodeIfPresent(String.self, forKey: .id) ?? UUID().uuidString
        text = try container.decode(String.self, forKey: .text)
        accessibilityText = try container.decodeIfPresent(String.self, forKey: .accessibilityText)
        fillColor = try container.decodeIfPresent(Badge.FillColor.self, forKey: .fillColor) ?? .red
        surface = try container.decodeIfPresent(Surface.self, forKey: .surface) ?? .light
        numberOfLines = try container.decodeIfPresent(Int.self, forKey: .numberOfLines) ?? 1
        maxWidth = try container.decodeIfPresent(CGFloat.self, forKey: .maxWidth)
    }
    
    public func encode(to encoder: Encoder) throws {
        var container = encoder.container(keyedBy: CodingKeys.self)
        try container.encode(id, forKey: .id)
        try container.encode(text, forKey: .text)
        try container.encode(accessibilityText, forKey: .accessibilityText)
        try container.encode(fillColor, forKey: .fillColor)
        try container.encode(surface, forKey: .surface)
        try container.encode(numberOfLines, forKey: .numberOfLines)
        try container.encodeIfPresent(maxWidth, forKey: .maxWidth)
    }
}
