// // TiletTitleModel.swift // VDS // // Created by Matt Bruce on 1/6/23. // import Foundation extension Tilelet { public struct TitleModel: Codable { //-------------------------------------------------- // MARK: - Enums //-------------------------------------------------- public enum TextStyle: String, EnumSubset, Codable { case titleXLarge case boldTitleXLarge case titleLarge case boldTitleLarge case titleMedium case boldTitleMedium case titleSmall case boldTitleSmall public var defaultValue: TitleLockup.TitleTextStyle { .boldTitleSmall } } //-------------------------------------------------- // MARK: - Public Properties //-------------------------------------------------- public var text: String = "" public var textStyle: TextStyle = .boldTitleSmall //-------------------------------------------------- // MARK: - Initializers //-------------------------------------------------- public init(text: String, textStyle: TextStyle = .boldTitleSmall) { self.text = text self.textStyle = textStyle } //-------------------------------------------------- // MARK: - Public Functions //-------------------------------------------------- public func toTitleLockupTitleModel() -> TitleLockup.TitleModel { TitleLockup.TitleModel(text: text, textAttributes: nil, textStyle: textStyle.value) } public init(from decoder: Decoder) throws { let container: KeyedDecodingContainer = try decoder.container(keyedBy: Tilelet.TitleModel.CodingKeys.self) self.text = try container.decode(String.self, forKey: Tilelet.TitleModel.CodingKeys.text) self.textStyle = try container.decodeIfPresent(Tilelet.TitleModel.TextStyle.self, forKey: Tilelet.TitleModel.CodingKeys.textStyle) ?? .boldTitleSmall } } }