DomainDig/Models.swift

1f58092dcb67cded75a850db364f3b46d86181f3
domain-dig/DomainDig/Models.swift history · blame · raw

754 lines · 25000 bytes

  1import Foundation
  2
  3enum ServiceResult<Value> {
  4    case success(Value)
  5    case empty(String)
  6    case error(String)
  7}
  8
  9enum DomainAvailabilityStatus: String, Codable {
 10    case available
 11    case registered
 12    case unknown
 13}
 14
 15struct DomainAvailabilityResult: Codable {
 16    let domain: String
 17    let status: DomainAvailabilityStatus
 18}
 19
 20struct DomainSuggestionResult: Identifiable, Codable {
 21    let id: UUID
 22    let domain: String
 23    let status: DomainAvailabilityStatus
 24
 25    init(id: UUID = UUID(), domain: String, status: DomainAvailabilityStatus) {
 26        self.id = id
 27        self.domain = domain
 28        self.status = status
 29    }
 30}
 31
 32struct WatchedDomain: Codable, Identifiable {
 33    let id: UUID
 34    let domain: String
 35    let createdAt: Date
 36    var lastKnownAvailability: DomainAvailabilityStatus?
 37
 38    init(
 39        id: UUID = UUID(),
 40        domain: String,
 41        createdAt: Date = Date(),
 42        lastKnownAvailability: DomainAvailabilityStatus? = nil
 43    ) {
 44        self.id = id
 45        self.domain = domain
 46        self.createdAt = createdAt
 47        self.lastKnownAvailability = lastKnownAvailability
 48    }
 49}
 50
 51enum ChangeSeverity: Int, Codable, CaseIterable, Comparable {
 52    case low
 53    case medium
 54    case high
 55
 56    static func < (lhs: ChangeSeverity, rhs: ChangeSeverity) -> Bool {
 57        lhs.rawValue < rhs.rawValue
 58    }
 59
 60    var title: String {
 61        switch self {
 62        case .low:
 63            return "Low"
 64        case .medium:
 65            return "Medium"
 66        case .high:
 67            return "High"
 68        }
 69    }
 70}
 71
 72enum CertificateWarningLevel: String, Codable {
 73    case none
 74    case warning
 75    case critical
 76
 77    var title: String {
 78        switch self {
 79        case .none:
 80            return "Healthy"
 81        case .warning:
 82            return "Warning"
 83        case .critical:
 84            return "Critical"
 85        }
 86    }
 87}
 88
 89struct DomainChangeSummary: Codable, Equatable {
 90    let hasChanges: Bool
 91    let changedSections: [String]
 92    let message: String
 93    let severity: ChangeSeverity
 94    let generatedAt: Date
 95
 96    init(
 97        hasChanges: Bool,
 98        changedSections: [String],
 99        message: String,
100        severity: ChangeSeverity,
101        generatedAt: Date
102    ) {
103        self.hasChanges = hasChanges
104        self.changedSections = changedSections
105        self.message = message
106        self.severity = severity
107        self.generatedAt = generatedAt
108    }
109
110    init(from decoder: Decoder) throws {
111        let container = try decoder.container(keyedBy: CodingKeys.self)
112        hasChanges = try container.decodeIfPresent(Bool.self, forKey: .hasChanges) ?? false
113        changedSections = try container.decodeIfPresent([String].self, forKey: .changedSections) ?? []
114        generatedAt = try container.decode(Date.self, forKey: .generatedAt)
115        severity = try container.decodeIfPresent(ChangeSeverity.self, forKey: .severity) ?? (hasChanges ? .medium : .low)
116        message = try container.decodeIfPresent(String.self, forKey: .message)
117            ?? (changedSections.isEmpty ? "No meaningful changes" : changedSections.joined(separator: " • "))
118    }
119}
120
121enum BatchLookupSource: String, Codable {
122    case manual
123    case watchlistRefresh
124}
125
126enum BatchLookupStatus: String, Codable {
127    case pending
128    case running
129    case completed
130    case failed
131}
132
133struct BatchLookupResult: Identifiable, Codable, Equatable {
134    let id: UUID
135    let domain: String
136    let historyEntryID: UUID?
137    let availability: DomainAvailabilityStatus?
138    let primaryIP: String?
139    let quickStatus: String
140    let summaryMessage: String?
141    let changeSeverity: ChangeSeverity?
142    let certificateWarningLevel: CertificateWarningLevel
143    let timestamp: Date
144    let status: BatchLookupStatus
145    let errorMessage: String?
146
147    init(
148        id: UUID = UUID(),
149        domain: String,
150        historyEntryID: UUID?,
151        availability: DomainAvailabilityStatus?,
152        primaryIP: String?,
153        quickStatus: String,
154        summaryMessage: String? = nil,
155        changeSeverity: ChangeSeverity? = nil,
156        certificateWarningLevel: CertificateWarningLevel = .none,
157        timestamp: Date,
158        status: BatchLookupStatus,
159        errorMessage: String? = nil
160    ) {
161        self.id = id
162        self.domain = domain
163        self.historyEntryID = historyEntryID
164        self.availability = availability
165        self.primaryIP = primaryIP
166        self.quickStatus = quickStatus
167        self.summaryMessage = summaryMessage
168        self.changeSeverity = changeSeverity
169        self.certificateWarningLevel = certificateWarningLevel
170        self.timestamp = timestamp
171        self.status = status
172        self.errorMessage = errorMessage
173    }
174}
175
176struct BatchSweepSummary: Identifiable, Equatable {
177    let id = UUID()
178    let source: BatchLookupSource
179    let totalDomains: Int
180    let changedDomains: Int
181    let unchangedDomains: Int
182    let warningDomains: Int
183    let results: [BatchLookupResult]
184    let generatedAt: Date
185}
186
187enum HistoryDateFilter: String, CaseIterable, Identifiable {
188    case today
189    case last7Days
190    case all
191
192    var id: String { rawValue }
193
194    var title: String {
195        switch self {
196        case .today:
197            return "Today"
198        case .last7Days:
199            return "Last 7 Days"
200        case .all:
201            return "All"
202        }
203    }
204}
205
206enum ChangeFilterOption: String, CaseIterable, Identifiable {
207    case all
208    case changed
209    case unchanged
210
211    var id: String { rawValue }
212
213    var title: String {
214        switch self {
215        case .all:
216            return "All"
217        case .changed:
218            return "Changed"
219        case .unchanged:
220            return "Unchanged"
221        }
222    }
223}
224
225enum HistorySortOption: String, CaseIterable, Identifiable {
226    case newest
227    case oldest
228    case domain
229
230    var id: String { rawValue }
231
232    var title: String {
233        switch self {
234        case .newest:
235            return "Newest"
236        case .oldest:
237            return "Oldest"
238        case .domain:
239            return "Domain A-Z"
240        }
241    }
242}
243
244enum WatchlistFilterOption: String, CaseIterable, Identifiable {
245    case all
246    case pinnedOnly
247    case changedOnly
248
249    var id: String { rawValue }
250
251    var title: String {
252        switch self {
253        case .all:
254            return "All"
255        case .pinnedOnly:
256            return "Pinned Only"
257        case .changedOnly:
258            return "Changed Only"
259        }
260    }
261}
262
263enum WatchlistSortOption: String, CaseIterable, Identifiable {
264    case pinned
265    case recentlyUpdated
266    case alphabetical
267
268    var id: String { rawValue }
269
270    var title: String {
271        switch self {
272        case .pinned:
273            return "Pinned"
274        case .recentlyUpdated:
275            return "Recently Updated"
276        case .alphabetical:
277            return "Alphabetical"
278        }
279    }
280}
281
282enum PremiumCapability: String, Codable {
283    case unlimitedTrackedDomains
284    case automatedMonitoring
285    case pushAlerts
286    case batchTracking
287    case advancedExports
288}
289
290struct TrackedDomain: Codable, Identifiable, Equatable {
291    let id: UUID
292    var domain: String
293    var createdAt: Date
294    var updatedAt: Date
295    var note: String?
296    var isPinned: Bool
297    var lastKnownAvailability: DomainAvailabilityStatus?
298    var lastSnapshotID: UUID?
299    var lastChangeSummary: DomainChangeSummary?
300    var lastChangeSeverity: ChangeSeverity?
301    var certificateWarningLevel: CertificateWarningLevel
302    var certificateDaysRemaining: Int?
303
304    init(
305        id: UUID = UUID(),
306        domain: String,
307        createdAt: Date = Date(),
308        updatedAt: Date = Date(),
309        note: String? = nil,
310        isPinned: Bool = false,
311        lastKnownAvailability: DomainAvailabilityStatus? = nil,
312        lastSnapshotID: UUID? = nil,
313        lastChangeSummary: DomainChangeSummary? = nil,
314        lastChangeSeverity: ChangeSeverity? = nil,
315        certificateWarningLevel: CertificateWarningLevel = .none,
316        certificateDaysRemaining: Int? = nil
317    ) {
318        self.id = id
319        self.domain = domain
320        self.createdAt = createdAt
321        self.updatedAt = updatedAt
322        self.note = note
323        self.isPinned = isPinned
324        self.lastKnownAvailability = lastKnownAvailability
325        self.lastSnapshotID = lastSnapshotID
326        self.lastChangeSummary = lastChangeSummary
327        self.lastChangeSeverity = lastChangeSeverity
328        self.certificateWarningLevel = certificateWarningLevel
329        self.certificateDaysRemaining = certificateDaysRemaining
330    }
331
332    init(from decoder: Decoder) throws {
333        let container = try decoder.container(keyedBy: CodingKeys.self)
334        id = try container.decodeIfPresent(UUID.self, forKey: .id) ?? UUID()
335        domain = try container.decode(String.self, forKey: .domain)
336        createdAt = try container.decodeIfPresent(Date.self, forKey: .createdAt) ?? Date()
337        updatedAt = try container.decodeIfPresent(Date.self, forKey: .updatedAt) ?? createdAt
338        note = try container.decodeIfPresent(String.self, forKey: .note)
339        isPinned = try container.decodeIfPresent(Bool.self, forKey: .isPinned) ?? false
340        lastKnownAvailability = try container.decodeIfPresent(DomainAvailabilityStatus.self, forKey: .lastKnownAvailability)
341        lastSnapshotID = try container.decodeIfPresent(UUID.self, forKey: .lastSnapshotID)
342        lastChangeSummary = try container.decodeIfPresent(DomainChangeSummary.self, forKey: .lastChangeSummary)
343        lastChangeSeverity = try container.decodeIfPresent(ChangeSeverity.self, forKey: .lastChangeSeverity) ?? lastChangeSummary?.severity
344        certificateWarningLevel = try container.decodeIfPresent(CertificateWarningLevel.self, forKey: .certificateWarningLevel) ?? .none
345        certificateDaysRemaining = try container.decodeIfPresent(Int.self, forKey: .certificateDaysRemaining)
346    }
347}
348
349// MARK: - DNS Models
350
351enum DNSRecordType: String, CaseIterable, Codable {
352    case A
353    case AAAA
354    case MX
355    case NS
356    case TXT
357    case CNAME
358    case SOA
359    case SRV
360    case CAA
361    case DS
362    case PTR
363
364    var queryType: Int {
365        switch self {
366        case .A: return 1
367        case .AAAA: return 28
368        case .MX: return 15
369        case .NS: return 2
370        case .TXT: return 16
371        case .CNAME: return 5
372        case .SOA: return 6
373        case .SRV: return 33
374        case .CAA: return 257
375        case .DS: return 43
376        case .PTR: return 12
377        }
378    }
379
380    var usesRawDataValue: Bool {
381        switch self {
382        case .TXT, .SOA, .DS:
383            return true
384        default:
385            return false
386        }
387    }
388}
389
390struct DNSRecord: Identifiable, Codable {
391    var id = UUID()
392    let value: String
393    let ttl: Int
394}
395
396struct DNSSection: Identifiable, Codable {
397    var id = UUID()
398    let recordType: DNSRecordType
399    var records: [DNSRecord]
400    var wildcardRecords: [DNSRecord] = []
401    var dnssecSigned: Bool?
402    var error: String?
403}
404
405// MARK: - SSL Models
406
407struct SSLCertificateInfo: Codable {
408    struct CertChainEntry: Codable {
409        let subject: String
410        let issuer: String
411    }
412
413    let commonName: String
414    let subjectAltNames: [String]
415    let issuer: String
416    let validFrom: Date
417    let validUntil: Date
418    let daysUntilExpiry: Int
419    let chainDepth: Int
420    let tlsVersion: String?
421    let cipherSuite: String?
422    let chain: [CertChainEntry]
423
424    init(
425        commonName: String,
426        subjectAltNames: [String],
427        issuer: String,
428        validFrom: Date,
429        validUntil: Date,
430        daysUntilExpiry: Int,
431        chainDepth: Int,
432        tlsVersion: String? = nil,
433        cipherSuite: String? = nil,
434        chain: [CertChainEntry] = []
435    ) {
436        self.commonName = commonName
437        self.subjectAltNames = subjectAltNames
438        self.issuer = issuer
439        self.validFrom = validFrom
440        self.validUntil = validUntil
441        self.daysUntilExpiry = daysUntilExpiry
442        self.chainDepth = chainDepth
443        self.tlsVersion = tlsVersion
444        self.cipherSuite = cipherSuite
445        self.chain = chain
446    }
447
448    init(from decoder: Decoder) throws {
449        let container = try decoder.container(keyedBy: CodingKeys.self)
450        commonName = try container.decode(String.self, forKey: .commonName)
451        subjectAltNames = try container.decode([String].self, forKey: .subjectAltNames)
452        issuer = try container.decode(String.self, forKey: .issuer)
453        validFrom = try container.decode(Date.self, forKey: .validFrom)
454        validUntil = try container.decode(Date.self, forKey: .validUntil)
455        daysUntilExpiry = try container.decode(Int.self, forKey: .daysUntilExpiry)
456        chainDepth = try container.decode(Int.self, forKey: .chainDepth)
457        tlsVersion = try container.decodeIfPresent(String.self, forKey: .tlsVersion)
458        cipherSuite = try container.decodeIfPresent(String.self, forKey: .cipherSuite)
459        chain = try container.decodeIfPresent([CertChainEntry].self, forKey: .chain) ?? []
460    }
461}
462
463// MARK: - HTTP Headers Models
464
465struct HTTPHeader: Identifiable, Codable {
466    var id = UUID()
467    let name: String
468    let value: String
469
470    static let securityHeaders: Set<String> = [
471        "strict-transport-security",
472        "x-frame-options",
473        "x-content-type-options",
474        "content-security-policy",
475        "referrer-policy"
476    ]
477
478    var isSecurityHeader: Bool {
479        Self.securityHeaders.contains(name.lowercased())
480    }
481}
482
483// MARK: - Reachability Models
484
485struct PortReachability: Identifiable, Codable {
486    var id = UUID()
487    let port: UInt16
488    let reachable: Bool
489    let latencyMs: Int?
490}
491
492// MARK: - IP Geolocation Models
493
494struct IPGeolocation: Codable {
495    let ip: String
496    let city: String?
497    let region: String?
498    let country_name: String?
499    let org: String?
500    let latitude: Double?
501    let longitude: Double?
502}
503
504// MARK: - Email Security Models
505
506struct EmailSecurityResult: Codable {
507    let spf: EmailSecurityRecord
508    let dmarc: EmailSecurityRecord
509    let dkim: EmailSecurityRecord
510    let bimi: EmailSecurityRecord
511    let mtaSts: MTASTSResult?
512
513    init(
514        spf: EmailSecurityRecord,
515        dmarc: EmailSecurityRecord,
516        dkim: EmailSecurityRecord,
517        bimi: EmailSecurityRecord = EmailSecurityRecord(found: false, value: nil),
518        mtaSts: MTASTSResult? = nil
519    ) {
520        self.spf = spf
521        self.dmarc = dmarc
522        self.dkim = dkim
523        self.bimi = bimi
524        self.mtaSts = mtaSts
525    }
526
527    init(from decoder: Decoder) throws {
528        let container = try decoder.container(keyedBy: CodingKeys.self)
529        spf = try container.decode(EmailSecurityRecord.self, forKey: .spf)
530        dmarc = try container.decode(EmailSecurityRecord.self, forKey: .dmarc)
531        dkim = try container.decode(EmailSecurityRecord.self, forKey: .dkim)
532        bimi = try container.decodeIfPresent(EmailSecurityRecord.self, forKey: .bimi)
533            ?? EmailSecurityRecord(found: false, value: nil)
534        mtaSts = try container.decodeIfPresent(MTASTSResult.self, forKey: .mtaSts)
535    }
536}
537
538struct EmailSecurityRecord: Codable {
539    let found: Bool
540    let value: String?
541    let matchedSelector: String?
542
543    init(found: Bool, value: String?, matchedSelector: String? = nil) {
544        self.found = found
545        self.value = value
546        self.matchedSelector = matchedSelector
547    }
548
549    init(from decoder: Decoder) throws {
550        let container = try decoder.container(keyedBy: CodingKeys.self)
551        found = try container.decode(Bool.self, forKey: .found)
552        value = try container.decodeIfPresent(String.self, forKey: .value)
553        matchedSelector = try container.decodeIfPresent(String.self, forKey: .matchedSelector)
554    }
555}
556
557struct MTASTSResult: Codable {
558    let txtFound: Bool
559    let policyMode: String?
560}
561
562// MARK: - Redirect Chain Models
563
564struct RedirectHop: Identifiable, Codable {
565    var id = UUID()
566    let stepNumber: Int
567    let statusCode: Int
568    let url: String
569    let isFinal: Bool
570}
571
572// MARK: - Port Scan Models
573
574enum PortScanKind: String, Codable {
575    case standard
576    case custom
577}
578
579struct PortScanResult: Identifiable, Codable {
580    var id = UUID()
581    let port: UInt16
582    let service: String
583    let open: Bool
584    var banner: String?
585    let kind: PortScanKind
586    let durationMs: Int?
587
588    nonisolated init(
589        port: UInt16,
590        service: String,
591        open: Bool,
592        banner: String? = nil,
593        kind: PortScanKind = .standard,
594        durationMs: Int? = nil
595    ) {
596        self.port = port
597        self.service = service
598        self.open = open
599        self.banner = banner
600        self.kind = kind
601        self.durationMs = durationMs
602    }
603
604    init(from decoder: Decoder) throws {
605        let container = try decoder.container(keyedBy: CodingKeys.self)
606        id = try container.decodeIfPresent(UUID.self, forKey: .id) ?? UUID()
607        port = try container.decode(UInt16.self, forKey: .port)
608        service = try container.decode(String.self, forKey: .service)
609        open = try container.decode(Bool.self, forKey: .open)
610        banner = try container.decodeIfPresent(String.self, forKey: .banner)
611        kind = try container.decodeIfPresent(PortScanKind.self, forKey: .kind) ?? .standard
612        durationMs = try container.decodeIfPresent(Int.self, forKey: .durationMs)
613    }
614}
615
616// MARK: - History Models
617
618struct HistoryEntry: Identifiable, Codable {
619    var id = UUID()
620    let domain: String
621    let timestamp: Date
622    var trackedDomainID: UUID?
623    let dnsSections: [DNSSection]
624    let sslInfo: SSLCertificateInfo?
625    let httpHeaders: [HTTPHeader]
626    let reachabilityResults: [PortReachability]
627    let ipGeolocation: IPGeolocation?
628    var emailSecurity: EmailSecurityResult?
629    var mtaSts: MTASTSResult?
630    var ptrRecord: String?
631    var redirectChain: [RedirectHop]
632    var portScanResults: [PortScanResult]
633    var hstsPreloaded: Bool?
634    var availabilityResult: DomainAvailabilityResult?
635    var suggestions: [DomainSuggestionResult]
636    var resolverDisplayName: String
637    var resolverURLString: String
638    var totalLookupDurationMs: Int?
639    var primaryIP: String?
640    var finalRedirectURL: String?
641    var tlsStatusSummary: String?
642    var emailSecuritySummary: String?
643    var httpGradeSummary: String?
644    var changeSummary: DomainChangeSummary?
645    var sslError: String?
646    var httpHeadersError: String?
647    var reachabilityError: String?
648    var ipGeolocationError: String?
649    var emailSecurityError: String?
650    var ptrError: String?
651    var redirectChainError: String?
652    var portScanError: String?
653
654    init(domain: String, timestamp: Date, trackedDomainID: UUID? = nil, dnsSections: [DNSSection],
655         sslInfo: SSLCertificateInfo?, httpHeaders: [HTTPHeader],
656         reachabilityResults: [PortReachability], ipGeolocation: IPGeolocation?,
657         emailSecurity: EmailSecurityResult? = nil, mtaSts: MTASTSResult? = nil, ptrRecord: String? = nil,
658         redirectChain: [RedirectHop] = [], portScanResults: [PortScanResult] = [],
659         hstsPreloaded: Bool? = nil, availabilityResult: DomainAvailabilityResult? = nil,
660         suggestions: [DomainSuggestionResult] = [], resolverDisplayName: String, resolverURLString: String,
661         totalLookupDurationMs: Int? = nil, primaryIP: String? = nil, finalRedirectURL: String? = nil,
662         tlsStatusSummary: String? = nil, emailSecuritySummary: String? = nil, httpGradeSummary: String? = nil,
663         changeSummary: DomainChangeSummary? = nil, sslError: String? = nil, httpHeadersError: String? = nil,
664         reachabilityError: String? = nil, ipGeolocationError: String? = nil,
665         emailSecurityError: String? = nil, ptrError: String? = nil,
666         redirectChainError: String? = nil, portScanError: String? = nil) {
667        self.domain = domain
668        self.timestamp = timestamp
669        self.trackedDomainID = trackedDomainID
670        self.dnsSections = dnsSections
671        self.sslInfo = sslInfo
672        self.httpHeaders = httpHeaders
673        self.reachabilityResults = reachabilityResults
674        self.ipGeolocation = ipGeolocation
675        self.emailSecurity = emailSecurity
676        self.mtaSts = mtaSts ?? emailSecurity?.mtaSts
677        self.ptrRecord = ptrRecord
678        self.redirectChain = redirectChain
679        self.portScanResults = portScanResults
680        self.hstsPreloaded = hstsPreloaded
681        self.availabilityResult = availabilityResult
682        self.suggestions = suggestions
683        self.resolverDisplayName = resolverDisplayName
684        self.resolverURLString = resolverURLString
685        self.totalLookupDurationMs = totalLookupDurationMs
686        self.primaryIP = primaryIP
687        self.finalRedirectURL = finalRedirectURL
688        self.tlsStatusSummary = tlsStatusSummary
689        self.emailSecuritySummary = emailSecuritySummary
690        self.httpGradeSummary = httpGradeSummary
691        self.changeSummary = changeSummary
692        self.sslError = sslError
693        self.httpHeadersError = httpHeadersError
694        self.reachabilityError = reachabilityError
695        self.ipGeolocationError = ipGeolocationError
696        self.emailSecurityError = emailSecurityError
697        self.ptrError = ptrError
698        self.redirectChainError = redirectChainError
699        self.portScanError = portScanError
700    }
701
702    init(from decoder: Decoder) throws {
703        let container = try decoder.container(keyedBy: CodingKeys.self)
704        id = try container.decodeIfPresent(UUID.self, forKey: .id) ?? UUID()
705        domain = try container.decode(String.self, forKey: .domain)
706        timestamp = try container.decode(Date.self, forKey: .timestamp)
707        trackedDomainID = try container.decodeIfPresent(UUID.self, forKey: .trackedDomainID)
708        dnsSections = try container.decode([DNSSection].self, forKey: .dnsSections)
709        sslInfo = try container.decodeIfPresent(SSLCertificateInfo.self, forKey: .sslInfo)
710        httpHeaders = try container.decode([HTTPHeader].self, forKey: .httpHeaders)
711        reachabilityResults = try container.decode([PortReachability].self, forKey: .reachabilityResults)
712        ipGeolocation = try container.decodeIfPresent(IPGeolocation.self, forKey: .ipGeolocation)
713        emailSecurity = try container.decodeIfPresent(EmailSecurityResult.self, forKey: .emailSecurity)
714        mtaSts = try container.decodeIfPresent(MTASTSResult.self, forKey: .mtaSts) ?? emailSecurity?.mtaSts
715        ptrRecord = try container.decodeIfPresent(String.self, forKey: .ptrRecord)
716        redirectChain = try container.decodeIfPresent([RedirectHop].self, forKey: .redirectChain) ?? []
717        portScanResults = try container.decodeIfPresent([PortScanResult].self, forKey: .portScanResults) ?? []
718        hstsPreloaded = try container.decodeIfPresent(Bool.self, forKey: .hstsPreloaded)
719        availabilityResult = try container.decodeIfPresent(DomainAvailabilityResult.self, forKey: .availabilityResult)
720        suggestions = try container.decodeIfPresent([DomainSuggestionResult].self, forKey: .suggestions) ?? []
721        resolverDisplayName = try container.decodeIfPresent(String.self, forKey: .resolverDisplayName) ?? "Cloudflare"
722        resolverURLString = try container.decodeIfPresent(String.self, forKey: .resolverURLString) ?? DNSResolverOption.defaultURLString
723        totalLookupDurationMs = try container.decodeIfPresent(Int.self, forKey: .totalLookupDurationMs)
724        primaryIP = try container.decodeIfPresent(String.self, forKey: .primaryIP)
725        finalRedirectURL = try container.decodeIfPresent(String.self, forKey: .finalRedirectURL)
726        tlsStatusSummary = try container.decodeIfPresent(String.self, forKey: .tlsStatusSummary)
727        emailSecuritySummary = try container.decodeIfPresent(String.self, forKey: .emailSecuritySummary)
728        httpGradeSummary = try container.decodeIfPresent(String.self, forKey: .httpGradeSummary)
729        changeSummary = try container.decodeIfPresent(DomainChangeSummary.self, forKey: .changeSummary)
730        sslError = try container.decodeIfPresent(String.self, forKey: .sslError)
731        httpHeadersError = try container.decodeIfPresent(String.self, forKey: .httpHeadersError)
732        reachabilityError = try container.decodeIfPresent(String.self, forKey: .reachabilityError)
733        ipGeolocationError = try container.decodeIfPresent(String.self, forKey: .ipGeolocationError)
734        emailSecurityError = try container.decodeIfPresent(String.self, forKey: .emailSecurityError)
735        ptrError = try container.decodeIfPresent(String.self, forKey: .ptrError)
736        redirectChainError = try container.decodeIfPresent(String.self, forKey: .redirectChainError)
737        portScanError = try container.decodeIfPresent(String.self, forKey: .portScanError)
738    }
739}
740
741// MARK: - Cloudflare DNS-over-HTTPS Response
742
743struct CloudflareDNSResponse: Decodable {
744    let Status: Int
745    let AD: Bool?
746    let Answer: [CloudflareDNSAnswer]?
747
748    struct CloudflareDNSAnswer: Decodable {
749        let name: String
750        let type: Int
751        let TTL: Int
752        let data: String
753    }
754}