// // TiletSubTitleModel.swift // VDS // // Created by Matt Bruce on 1/6/23. // import Foundation extension Tilelet { public struct SubTitleModel { //-------------------------------------------------- // MARK: - Enums //-------------------------------------------------- public enum TextStyle: String, EnumSubset, Codable { 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 textAttributes: [any LabelAttributeModel]? 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.textAttributes = textAttributes self.textColor = textColor self.textStyle = textStyle } //-------------------------------------------------- // MARK: - Public Functions //-------------------------------------------------- public func toTitleLockupSubTitleModel() -> TitleLockup.SubTitleModel { TitleLockup.SubTitleModel(text: text, textColor: textColor, textAttributes: nil) } } } extension Tilelet.SubTitleModel: Codable { private enum CodingKeys: String, CodingKey { case text, textStyle, textColor } public init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) self.text = try container.decode(String.self, forKey: .text) self.textStyle = try container.decodeIfPresent(TextStyle.self, forKey: .textStyle) ?? .bodySmall self.textColor = try container.decodeIfPresent(Use.self, forKey: .textColor) ?? .primary } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(text, forKey: .text) try container.encode(textStyle, forKey: .textStyle) try container.encode(textColor, forKey: .textColor) } }