vds_ios/VDS/Components/Tilet/TiletSubTitleModel.swift
Matt Bruce 09c0a567e1 added default values in the decoder func
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
2023-01-17 10:01:01 -06:00

62 lines
2.4 KiB
Swift

//
// TiletSubTitleModel.swift
// VDS
//
// Created by Matt Bruce on 1/6/23.
//
import Foundation
extension Tilet {
public struct SubTitleModel: Codable {
//--------------------------------------------------
// MARK: - Enums
//--------------------------------------------------
public enum TextStyle: String, Codable, EnumSubset {
case bodyLarge
case boldBodyLarge
case bodyMedium
case boldBodyMedium
case bodySmall
case boldBodySmall
public var defaultValue: TitleLockup.OtherTextStyle { .bodySmall }
}
//--------------------------------------------------
// MARK: - Public Properties
//--------------------------------------------------
public var text: String = ""
public var textStyle: TextStyle = .bodySmall
public var textColor: Use = .primary
//--------------------------------------------------
// MARK: - Initializers
//--------------------------------------------------
public init(text: String,
textColor: Use = .primary,
textAttributes: [any LabelAttributeModel]? = nil,
textStyle: TextStyle = .bodySmall) {
self.text = text
self.textColor = textColor
self.textStyle = textStyle
}
//--------------------------------------------------
// MARK: - Public Functions
//--------------------------------------------------
public func toTitleLockupSubTitleModel() -> TitleLockup.SubTitleModel {
TitleLockup.SubTitleModel(text: text,
textColor: textColor,
textAttributes: nil)
}
public init(from decoder: Decoder) throws {
let container: KeyedDecodingContainer<Tilet.SubTitleModel.CodingKeys> = try decoder.container(keyedBy: Tilet.SubTitleModel.CodingKeys.self)
self.text = try container.decode(String.self, forKey: Tilet.SubTitleModel.CodingKeys.text)
self.textStyle = try container.decodeIfPresent(Tilet.SubTitleModel.TextStyle.self, forKey: Tilet.SubTitleModel.CodingKeys.textStyle) ?? .bodySmall
self.textColor = try container.decodeIfPresent(Use.self, forKey: Tilet.SubTitleModel.CodingKeys.textColor) ?? .primary
}
}
}