Files
divkit/client/ios/DivKit/generated_sources/DivPhoneInputMaskTemplate.swift
T
feldspar ce9af20a5b Revert parsing logic update
commit_hash:c9419f063b7f8c5df41675acc9ed49d862850a2c
2026-01-16 23:06:00 +03:00

94 lines
3.5 KiB
Swift

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