// Generated code. Do not modify. import Foundation import Serialization import VGSL public final class DivTextRangeMaskSolidTemplate: TemplateValue, Sendable { public static let type: String = "solid" public let parent: String? public let color: Field>? public let isEnabled: Field>? // default value: true public convenience init(dictionary: [String: Any], templateToType: [TemplateName: String]) throws { self.init( parent: dictionary["type"] as? String, color: dictionary.getOptionalExpressionField("color", transform: Color.color(withHexString:)), isEnabled: dictionary.getOptionalExpressionField("is_enabled") ) } init( parent: String?, color: Field>? = nil, isEnabled: Field>? = nil ) { self.parent = parent self.color = color self.isEnabled = isEnabled } private static func resolveOnlyLinks(context: TemplatesContext, parent: DivTextRangeMaskSolidTemplate?) -> DeserializationResult { let colorValue = parent?.color?.resolveValue(context: context, transform: Color.color(withHexString:)) ?? .noValue let isEnabledValue = parent?.isEnabled?.resolveOptionalValue(context: context) ?? .noValue var errors = mergeErrors( colorValue.errorsOrWarnings?.map { .nestedObjectError(field: "color", error: $0) }, isEnabledValue.errorsOrWarnings?.map { .nestedObjectError(field: "is_enabled", error: $0) } ) if case .noValue = colorValue { errors.append(.requiredFieldIsMissing(field: "color")) } guard let colorNonNil = colorValue.value else { return .failure(NonEmptyArray(errors)!) } let result = DivTextRangeMaskSolid( color: colorNonNil, isEnabled: isEnabledValue.value ) return errors.isEmpty ? .success(result) : .partialSuccess(result, warnings: NonEmptyArray(errors)!) } public static func resolveValue(context: TemplatesContext, parent: DivTextRangeMaskSolidTemplate?, useOnlyLinks: Bool) -> DeserializationResult { if useOnlyLinks { return resolveOnlyLinks(context: context, parent: parent) } var colorValue: DeserializationResult> = parent?.color?.value() ?? .noValue var isEnabledValue: DeserializationResult> = parent?.isEnabled?.value() ?? .noValue context.templateData.forEach { key, __dictValue in switch key { case "color": colorValue = deserialize(__dictValue, transform: Color.color(withHexString:)).merged(with: colorValue) case "is_enabled": isEnabledValue = deserialize(__dictValue).merged(with: isEnabledValue) case parent?.color?.link: colorValue = colorValue.merged(with: { deserialize(__dictValue, transform: Color.color(withHexString:)) }) case parent?.isEnabled?.link: isEnabledValue = isEnabledValue.merged(with: { deserialize(__dictValue) }) default: break } } var errors = mergeErrors( colorValue.errorsOrWarnings?.map { .nestedObjectError(field: "color", error: $0) }, isEnabledValue.errorsOrWarnings?.map { .nestedObjectError(field: "is_enabled", error: $0) } ) if case .noValue = colorValue { errors.append(.requiredFieldIsMissing(field: "color")) } guard let colorNonNil = colorValue.value else { return .failure(NonEmptyArray(errors)!) } let result = DivTextRangeMaskSolid( color: colorNonNil, isEnabled: isEnabledValue.value ) return errors.isEmpty ? .success(result) : .partialSuccess(result, warnings: NonEmptyArray(errors)!) } private func mergedWithParent(templates: [TemplateName: Any]) throws -> DivTextRangeMaskSolidTemplate { guard let parent = parent, parent != Self.type else { return self } guard let parentTemplate = templates[parent] as? DivTextRangeMaskSolidTemplate else { throw DeserializationError.unknownType(type: parent) } let mergedParent = try parentTemplate.mergedWithParent(templates: templates) return DivTextRangeMaskSolidTemplate( parent: nil, color: color ?? mergedParent.color, isEnabled: isEnabled ?? mergedParent.isEnabled ) } public func resolveParent(templates: [TemplateName: Any]) throws -> DivTextRangeMaskSolidTemplate { return try mergedWithParent(templates: templates) } }