api-swift / Sources / IrdAPI / Generated / Domains.swift
3,741 words
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
// Generated by scripts/gen-api.py from spec/openapi.json — do not edit.

import Foundation

// MARK: - Types

/// Values this build does not know decode as `.unrecognized`.
public enum DomainAvailability: RawRepresentable, Codable, Sendable, Hashable {
    case available
    case registered
    case reserved
    case unknown
    /// A value the server sent that this version of the package does not list.
    case unrecognized(String)

    /// Every value the spec listed when this file was generated.
    public static let known: [DomainAvailability] = [.available, .registered, .reserved, .unknown]

    public init(rawValue: String) {
        switch rawValue {
        case "available": self = .available
        case "registered": self = .registered
        case "reserved": self = .reserved
        case "unknown": self = .unknown
        default: self = .unrecognized(rawValue)
        }
    }

    public var rawValue: String {
        switch self {
        case .available: return "available"
        case .registered: return "registered"
        case .reserved: return "reserved"
        case .unknown: return "unknown"
        case .unrecognized(let raw): return raw
        }
    }

    public init(from decoder: any Decoder) throws {
        self.init(rawValue: try decoder.singleValueContainer().decode(String.self))
    }

    public func encode(to encoder: any Encoder) throws {
        var container = encoder.singleValueContainer()
        try container.encode(rawValue)
    }
}

/// Used by GET /domains/check.
public struct CheckResponse: Codable, Sendable, Hashable {
    public var domain: String
    public var tld: String
    public var status: DomainAvailability
    public var expiresAt: String?
    public var nameservers: [String]?
    public var checkedAt: String?

    public init(domain: String, tld: String, status: DomainAvailability, expiresAt: String? = nil, nameservers: [String]? = nil, checkedAt: String? = nil) {
        self.domain = domain
        self.tld = tld
        self.status = status
        self.expiresAt = expiresAt
        self.nameservers = nameservers
        self.checkedAt = checkedAt
    }

    enum CodingKeys: String, CodingKey {
        case domain
        case tld
        case status
        case expiresAt = "expires_at"
        case nameservers
        case checkedAt = "checked_at"
    }

    /// Explicit so required-but-nullable fields encode as `null` rather than vanishing.
    public func encode(to encoder: any Encoder) throws {
        var container = encoder.container(keyedBy: CodingKeys.self)
        try container.encode(domain, forKey: .domain)
        try container.encode(tld, forKey: .tld)
        try container.encode(status, forKey: .status)
        try container.encode(expiresAt, forKey: .expiresAt)
        try container.encode(nameservers, forKey: .nameservers)
        try container.encode(checkedAt, forKey: .checkedAt)
    }
}

/// Used by GET /domains/info.
public struct InfoResponse: Codable, Sendable, Hashable {
    public var domain: String
    public var tld: String
    public var whois: [String: JSONValue]?
    public var dns: [String: JSONValue]?
    public var subdomains: [String: JSONValue]?
    public var registry: [String: JSONValue]?

    public init(domain: String, tld: String, whois: [String: JSONValue]? = nil, dns: [String: JSONValue]? = nil, subdomains: [String: JSONValue]? = nil, registry: [String: JSONValue]? = nil) {
        self.domain = domain
        self.tld = tld
        self.whois = whois
        self.dns = dns
        self.subdomains = subdomains
        self.registry = registry
    }

    enum CodingKeys: String, CodingKey {
        case domain
        case tld
        case whois
        case dns
        case subdomains
        case registry
    }
}

/// Values this build does not know decode as `.unrecognized`.
public enum PreflightVerdict: RawRepresentable, Codable, Sendable, Hashable {
    case adopt
    case tradeIn
    case transferOrAcquire
    case register
    case alreadyYours
    case unavailable
    case unknown
    /// A value the server sent that this version of the package does not list.
    case unrecognized(String)

    /// Every value the spec listed when this file was generated.
    public static let known: [PreflightVerdict] = [.adopt, .tradeIn, .transferOrAcquire, .register, .alreadyYours, .unavailable, .unknown]

    public init(rawValue: String) {
        switch rawValue {
        case "adopt": self = .adopt
        case "trade-in": self = .tradeIn
        case "transfer-or-acquire": self = .transferOrAcquire
        case "register": self = .register
        case "already-yours": self = .alreadyYours
        case "unavailable": self = .unavailable
        case "unknown": self = .unknown
        default: self = .unrecognized(rawValue)
        }
    }

    public var rawValue: String {
        switch self {
        case .adopt: return "adopt"
        case .tradeIn: return "trade-in"
        case .transferOrAcquire: return "transfer-or-acquire"
        case .register: return "register"
        case .alreadyYours: return "already-yours"
        case .unavailable: return "unavailable"
        case .unknown: return "unknown"
        case .unrecognized(let raw): return raw
        }
    }

    public init(from decoder: any Decoder) throws {
        self.init(rawValue: try decoder.singleValueContainer().decode(String.self))
    }

    public func encode(to encoder: any Encoder) throws {
        var container = encoder.singleValueContainer()
        try container.encode(rawValue)
    }
}

/// Values this build does not know decode as `.unrecognized`.
public enum PreflightSponsorship: RawRepresentable, Codable, Sendable, Hashable {
    case ird
    case external
    case unregistered
    case unknown
    /// A value the server sent that this version of the package does not list.
    case unrecognized(String)

    /// Every value the spec listed when this file was generated.
    public static let known: [PreflightSponsorship] = [.ird, .external, .unregistered, .unknown]

    public init(rawValue: String) {
        switch rawValue {
        case "ird": self = .ird
        case "external": self = .external
        case "unregistered": self = .unregistered
        case "unknown": self = .unknown
        default: self = .unrecognized(rawValue)
        }
    }

    public var rawValue: String {
        switch self {
        case .ird: return "ird"
        case .external: return "external"
        case .unregistered: return "unregistered"
        case .unknown: return "unknown"
        case .unrecognized(let raw): return raw
        }
    }

    public init(from decoder: any Decoder) throws {
        self.init(rawValue: try decoder.singleValueContainer().decode(String.self))
    }

    public func encode(to encoder: any Encoder) throws {
        var container = encoder.singleValueContainer()
        try container.encode(rawValue)
    }
}

/// Used by GET /domains/preflight.
public struct PreflightResponse: Codable, Sendable, Hashable {
    public var domain: String
    public var verdict: PreflightVerdict
    public var sponsorship: PreflightSponsorship?
    public var registrantControlled: Bool?
    public var registrantEmailHint: String?
    public var expiresAt: String?
    public var registrationId: String?

    public init(domain: String, verdict: PreflightVerdict, sponsorship: PreflightSponsorship? = nil, registrantControlled: Bool? = nil, registrantEmailHint: String? = nil, expiresAt: String? = nil, registrationId: String? = nil) {
        self.domain = domain
        self.verdict = verdict
        self.sponsorship = sponsorship
        self.registrantControlled = registrantControlled
        self.registrantEmailHint = registrantEmailHint
        self.expiresAt = expiresAt
        self.registrationId = registrationId
    }

    enum CodingKeys: String, CodingKey {
        case domain
        case verdict
        case sponsorship
        case registrantControlled = "registrant_controlled"
        case registrantEmailHint = "registrant_email_hint"
        case expiresAt = "expires_at"
        case registrationId = "registration_id"
    }

    /// Explicit so required-but-nullable fields encode as `null` rather than vanishing.
    public func encode(to encoder: any Encoder) throws {
        var container = encoder.container(keyedBy: CodingKeys.self)
        try container.encode(domain, forKey: .domain)
        try container.encode(verdict, forKey: .verdict)
        try container.encode(sponsorship, forKey: .sponsorship)
        try container.encode(registrantControlled, forKey: .registrantControlled)
        try container.encode(registrantEmailHint, forKey: .registrantEmailHint)
        try container.encode(expiresAt, forKey: .expiresAt)
        try container.encode(registrationId, forKey: .registrationId)
    }
}

/// Used by GET /domains/dns-snapshot.
public struct SnapshotRecord: Codable, Sendable, Hashable {
    public var name: String
    public var type: String
    public var `class`: String
    public var ttl: Int
    public var data: [String: JSONValue]

    public init(name: String, type: String, `class`: String, ttl: Int, data: [String: JSONValue]) {
        self.name = name
        self.type = type
        self.`class` = `class`
        self.ttl = ttl
        self.data = data
    }

    enum CodingKeys: String, CodingKey {
        case name
        case type
        case `class`
        case ttl
        case data
    }
}

/// Used by GET /domains/dns-snapshot.
public struct DnsSnapshotResponse: Codable, Sendable, Hashable, Identifiable {
    public var id: String
    public var domain: String
    public var tld: String
    public var nameservers: [String]
    public var records: [SnapshotRecord]
    public var meta: [String: JSONValue]?
    public var takenAt: String

    public init(id: String, domain: String, tld: String, nameservers: [String], records: [SnapshotRecord], meta: [String: JSONValue]? = nil, takenAt: String) {
        self.id = id
        self.domain = domain
        self.tld = tld
        self.nameservers = nameservers
        self.records = records
        self.meta = meta
        self.takenAt = takenAt
    }

    enum CodingKeys: String, CodingKey {
        case id
        case domain
        case tld
        case nameservers
        case records
        case meta
        case takenAt = "taken_at"
    }

    /// Explicit so required-but-nullable fields encode as `null` rather than vanishing.
    public func encode(to encoder: any Encoder) throws {
        var container = encoder.container(keyedBy: CodingKeys.self)
        try container.encode(id, forKey: .id)
        try container.encode(domain, forKey: .domain)
        try container.encode(tld, forKey: .tld)
        try container.encode(nameservers, forKey: .nameservers)
        try container.encode(records, forKey: .records)
        try container.encode(meta, forKey: .meta)
        try container.encode(takenAt, forKey: .takenAt)
    }
}

/// Shared by 2 operations.
public struct Suggestion: Codable, Sendable, Hashable {
    public var domain: String
    public var tld: String
    public var status: DomainAvailability
    public var expiresAt: String?
    public var servedFrom: String?
    public var error: String?

    public init(domain: String, tld: String, status: DomainAvailability, expiresAt: String? = nil, servedFrom: String? = nil, error: String? = nil) {
        self.domain = domain
        self.tld = tld
        self.status = status
        self.expiresAt = expiresAt
        self.servedFrom = servedFrom
        self.error = error
    }

    enum CodingKeys: String, CodingKey {
        case domain
        case tld
        case status
        case expiresAt = "expires_at"
        case servedFrom = "served_from"
        case error
    }

    /// Explicit so required-but-nullable fields encode as `null` rather than vanishing.
    public func encode(to encoder: any Encoder) throws {
        var container = encoder.container(keyedBy: CodingKeys.self)
        try container.encode(domain, forKey: .domain)
        try container.encode(tld, forKey: .tld)
        try container.encode(status, forKey: .status)
        try container.encode(expiresAt, forKey: .expiresAt)
        try container.encode(servedFrom, forKey: .servedFrom)
        try container.encodeIfPresent(error, forKey: .error)
    }
}

/// Shared by 2 operations.
public struct SearchResponse: Codable, Sendable, Hashable {
    public var query: String
    public var suggestions: [Suggestion]

    public init(query: String, suggestions: [Suggestion]) {
        self.query = query
        self.suggestions = suggestions
    }

    enum CodingKeys: String, CodingKey {
        case query
        case suggestions
    }
}

/// Used by POST /domains/search.
public struct SearchDescriptionsBody: Codable, Sendable, Hashable {
    public var q: String
    public var count: Int?

    public init(q: String, count: Int? = nil) {
        self.q = q
        self.count = count
    }

    enum CodingKeys: String, CodingKey {
        case q
        case count
    }
}

/// Values this build does not know decode as `.unrecognized`.
public enum DirectoryEntryCategory: RawRepresentable, Codable, Sendable, Hashable {
    case newsMedia
    case government
    case education
    case health
    case eCommerce
    case businessServices
    case finance
    case technology
    case travelTourism
    case realEstate
    case auto
    case legal
    case cultureArts
    case sports
    case entertainment
    case foodRestaurants
    case religion
    case ngoNonprofit
    case blogPersonal
    case adult
    case gambling
    case parkedForSale
    case other
    /// A value the server sent that this version of the package does not list.
    case unrecognized(String)

    /// Every value the spec listed when this file was generated.
    public static let known: [DirectoryEntryCategory] = [.newsMedia, .government, .education, .health, .eCommerce, .businessServices, .finance, .technology, .travelTourism, .realEstate, .auto, .legal, .cultureArts, .sports, .entertainment, .foodRestaurants, .religion, .ngoNonprofit, .blogPersonal, .adult, .gambling, .parkedForSale, .other]

    public init(rawValue: String) {
        switch rawValue {
        case "news-media": self = .newsMedia
        case "government": self = .government
        case "education": self = .education
        case "health": self = .health
        case "e-commerce": self = .eCommerce
        case "business-services": self = .businessServices
        case "finance": self = .finance
        case "technology": self = .technology
        case "travel-tourism": self = .travelTourism
        case "real-estate": self = .realEstate
        case "auto": self = .auto
        case "legal": self = .legal
        case "culture-arts": self = .cultureArts
        case "sports": self = .sports
        case "entertainment": self = .entertainment
        case "food-restaurants": self = .foodRestaurants
        case "religion": self = .religion
        case "ngo-nonprofit": self = .ngoNonprofit
        case "blog-personal": self = .blogPersonal
        case "adult": self = .adult
        case "gambling": self = .gambling
        case "parked-for-sale": self = .parkedForSale
        case "other": self = .other
        default: self = .unrecognized(rawValue)
        }
    }

    public var rawValue: String {
        switch self {
        case .newsMedia: return "news-media"
        case .government: return "government"
        case .education: return "education"
        case .health: return "health"
        case .eCommerce: return "e-commerce"
        case .businessServices: return "business-services"
        case .finance: return "finance"
        case .technology: return "technology"
        case .travelTourism: return "travel-tourism"
        case .realEstate: return "real-estate"
        case .auto: return "auto"
        case .legal: return "legal"
        case .cultureArts: return "culture-arts"
        case .sports: return "sports"
        case .entertainment: return "entertainment"
        case .foodRestaurants: return "food-restaurants"
        case .religion: return "religion"
        case .ngoNonprofit: return "ngo-nonprofit"
        case .blogPersonal: return "blog-personal"
        case .adult: return "adult"
        case .gambling: return "gambling"
        case .parkedForSale: return "parked-for-sale"
        case .other: return "other"
        case .unrecognized(let raw): return raw
        }
    }

    public init(from decoder: any Decoder) throws {
        self.init(rawValue: try decoder.singleValueContainer().decode(String.self))
    }

    public func encode(to encoder: any Encoder) throws {
        var container = encoder.singleValueContainer()
        try container.encode(rawValue)
    }
}

/// Values this build does not know decode as `.unrecognized`.
public enum DirectoryEntryPoliticalBias: RawRepresentable, Codable, Sendable, Hashable {
    case left
    case centerLeft
    case center
    case centerRight
    case right
    /// A value the server sent that this version of the package does not list.
    case unrecognized(String)

    /// Every value the spec listed when this file was generated.
    public static let known: [DirectoryEntryPoliticalBias] = [.left, .centerLeft, .center, .centerRight, .right]

    public init(rawValue: String) {
        switch rawValue {
        case "left": self = .left
        case "center-left": self = .centerLeft
        case "center": self = .center
        case "center-right": self = .centerRight
        case "right": self = .right
        default: self = .unrecognized(rawValue)
        }
    }

    public var rawValue: String {
        switch self {
        case .left: return "left"
        case .centerLeft: return "center-left"
        case .center: return "center"
        case .centerRight: return "center-right"
        case .right: return "right"
        case .unrecognized(let raw): return raw
        }
    }

    public init(from decoder: any Decoder) throws {
        self.init(rawValue: try decoder.singleValueContainer().decode(String.self))
    }

    public func encode(to encoder: any Encoder) throws {
        var container = encoder.singleValueContainer()
        try container.encode(rawValue)
    }
}

/// Values this build does not know decode as `.unrecognized`.
public enum DirectoryEntrySentiment: RawRepresentable, Codable, Sendable, Hashable {
    case positive
    case neutral
    case negative
    case mixed
    /// A value the server sent that this version of the package does not list.
    case unrecognized(String)

    /// Every value the spec listed when this file was generated.
    public static let known: [DirectoryEntrySentiment] = [.positive, .neutral, .negative, .mixed]

    public init(rawValue: String) {
        switch rawValue {
        case "positive": self = .positive
        case "neutral": self = .neutral
        case "negative": self = .negative
        case "mixed": self = .mixed
        default: self = .unrecognized(rawValue)
        }
    }

    public var rawValue: String {
        switch self {
        case .positive: return "positive"
        case .neutral: return "neutral"
        case .negative: return "negative"
        case .mixed: return "mixed"
        case .unrecognized(let raw): return raw
        }
    }

    public init(from decoder: any Decoder) throws {
        self.init(rawValue: try decoder.singleValueContainer().decode(String.self))
    }

    public func encode(to encoder: any Encoder) throws {
        var container = encoder.singleValueContainer()
        try container.encode(rawValue)
    }
}

/// Shared by 2 operations.
public struct DirectoryEntry: Codable, Sendable, Hashable {
    public var domain: String
    public var title: String?
    public var description: String?
    public var language: String?
    public var categories: [DirectoryEntryCategory]
    public var tags: [String]
    public var politicalBias: DirectoryEntryPoliticalBias?
    public var sentiment: DirectoryEntrySentiment?
    public var contacts: [String: JSONValue]?
    public var adNetworks: [String]
    public var trackers: [String]
    public var tagManagers: [String]
    public var cookieConsent: Bool?
    public var cookieConsentPlatform: String?
    public var firstSeenAt: String?
    public var classifiedAt: String?

    public init(domain: String, title: String? = nil, description: String? = nil, language: String? = nil, categories: [DirectoryEntryCategory], tags: [String], politicalBias: DirectoryEntryPoliticalBias? = nil, sentiment: DirectoryEntrySentiment? = nil, contacts: [String: JSONValue]? = nil, adNetworks: [String], trackers: [String], tagManagers: [String], cookieConsent: Bool? = nil, cookieConsentPlatform: String? = nil, firstSeenAt: String? = nil, classifiedAt: String? = nil) {
        self.domain = domain
        self.title = title
        self.description = description
        self.language = language
        self.categories = categories
        self.tags = tags
        self.politicalBias = politicalBias
        self.sentiment = sentiment
        self.contacts = contacts
        self.adNetworks = adNetworks
        self.trackers = trackers
        self.tagManagers = tagManagers
        self.cookieConsent = cookieConsent
        self.cookieConsentPlatform = cookieConsentPlatform
        self.firstSeenAt = firstSeenAt
        self.classifiedAt = classifiedAt
    }

    enum CodingKeys: String, CodingKey {
        case domain
        case title
        case description
        case language
        case categories
        case tags
        case politicalBias = "political_bias"
        case sentiment
        case contacts
        case adNetworks = "ad_networks"
        case trackers
        case tagManagers = "tag_managers"
        case cookieConsent = "cookie_consent"
        case cookieConsentPlatform = "cookie_consent_platform"
        case firstSeenAt = "first_seen_at"
        case classifiedAt = "classified_at"
    }

    /// Explicit so required-but-nullable fields encode as `null` rather than vanishing.
    public func encode(to encoder: any Encoder) throws {
        var container = encoder.container(keyedBy: CodingKeys.self)
        try container.encode(domain, forKey: .domain)
        try container.encode(title, forKey: .title)
        try container.encode(description, forKey: .description)
        try container.encode(language, forKey: .language)
        try container.encode(categories, forKey: .categories)
        try container.encode(tags, forKey: .tags)
        try container.encode(politicalBias, forKey: .politicalBias)
        try container.encode(sentiment, forKey: .sentiment)
        try container.encode(contacts, forKey: .contacts)
        try container.encode(adNetworks, forKey: .adNetworks)
        try container.encode(trackers, forKey: .trackers)
        try container.encode(tagManagers, forKey: .tagManagers)
        try container.encode(cookieConsent, forKey: .cookieConsent)
        try container.encode(cookieConsentPlatform, forKey: .cookieConsentPlatform)
        try container.encode(firstSeenAt, forKey: .firstSeenAt)
        try container.encode(classifiedAt, forKey: .classifiedAt)
    }
}

/// Used by GET /domains/directory.
public struct DirectoryResponse: Codable, Sendable, Hashable {
    public var entries: [DirectoryEntry]
    public var nextCursor: String?
    public var total: Int?

    public init(entries: [DirectoryEntry], nextCursor: String? = nil, total: Int? = nil) {
        self.entries = entries
        self.nextCursor = nextCursor
        self.total = total
    }

    enum CodingKeys: String, CodingKey {
        case entries
        case nextCursor = "next_cursor"
        case total
    }

    /// Explicit so required-but-nullable fields encode as `null` rather than vanishing.
    public func encode(to encoder: any Encoder) throws {
        var container = encoder.container(keyedBy: CodingKeys.self)
        try container.encode(entries, forKey: .entries)
        try container.encode(nextCursor, forKey: .nextCursor)
        try container.encodeIfPresent(total, forKey: .total)
    }
}

/// Query parameters of `info`; unset fields are omitted.
public struct InfoQuery: Sendable, Hashable {
    public var fields: String?

    public init(fields: String? = nil) {
        self.fields = fields
    }

    /// The items in spec order.
    public var queryItems: [QueryItem] {
        var items: [QueryItem] = []
        if let value = fields { items.append(QueryItem("fields", value)) }
        return items
    }
}

/// Query parameters of `dnsSnapshot`; unset fields are omitted.
public struct DnsSnapshotQuery: Sendable, Hashable {
    public var subdomains: Bool?
    public var names: String?

    public init(subdomains: Bool? = nil, names: String? = nil) {
        self.subdomains = subdomains
        self.names = names
    }

    /// The items in spec order.
    public var queryItems: [QueryItem] {
        var items: [QueryItem] = []
        if let value = subdomains { items.append(QueryItem("subdomains", value ? "true" : "false")) }
        if let value = names { items.append(QueryItem("names", value)) }
        return items
    }
}

/// Query parameters of `search`; unset fields are omitted.
public struct SearchQuery: Sendable, Hashable {
    public var count: Int?

    public init(count: Int? = nil) {
        self.count = count
    }

    /// The items in spec order.
    public var queryItems: [QueryItem] {
        var items: [QueryItem] = []
        if let value = count { items.append(QueryItem("count", String(value))) }
        return items
    }
}

/// Query parameters of `directory`; unset fields are omitted.
public struct DirectoryQuery: Sendable, Hashable {
    public var category: DirectoryEntryCategory?
    public var tag: String?
    public var bias: DirectoryEntryPoliticalBias?
    public var sentiment: DirectoryEntrySentiment?
    public var language: String?
    public var adNetwork: String?
    public var tracker: String?
    public var tagManager: String?
    public var cookieConsent: Bool?
    public var q: String?
    public var limit: Int?
    public var cursor: String?
    public var offset: Int?
    public var includeTotal: Bool?

    public init(category: DirectoryEntryCategory? = nil, tag: String? = nil, bias: DirectoryEntryPoliticalBias? = nil, sentiment: DirectoryEntrySentiment? = nil, language: String? = nil, adNetwork: String? = nil, tracker: String? = nil, tagManager: String? = nil, cookieConsent: Bool? = nil, q: String? = nil, limit: Int? = nil, cursor: String? = nil, offset: Int? = nil, includeTotal: Bool? = nil) {
        self.category = category
        self.tag = tag
        self.bias = bias
        self.sentiment = sentiment
        self.language = language
        self.adNetwork = adNetwork
        self.tracker = tracker
        self.tagManager = tagManager
        self.cookieConsent = cookieConsent
        self.q = q
        self.limit = limit
        self.cursor = cursor
        self.offset = offset
        self.includeTotal = includeTotal
    }

    /// The items in spec order.
    public var queryItems: [QueryItem] {
        var items: [QueryItem] = []
        if let value = category { items.append(QueryItem("category", value.rawValue)) }
        if let value = tag { items.append(QueryItem("tag", value)) }
        if let value = bias { items.append(QueryItem("bias", value.rawValue)) }
        if let value = sentiment { items.append(QueryItem("sentiment", value.rawValue)) }
        if let value = language { items.append(QueryItem("language", value)) }
        if let value = adNetwork { items.append(QueryItem("ad_network", value)) }
        if let value = tracker { items.append(QueryItem("tracker", value)) }
        if let value = tagManager { items.append(QueryItem("tag_manager", value)) }
        if let value = cookieConsent { items.append(QueryItem("cookie_consent", value ? "true" : "false")) }
        if let value = q { items.append(QueryItem("q", value)) }
        if let value = limit { items.append(QueryItem("limit", String(value))) }
        if let value = cursor { items.append(QueryItem("cursor", value)) }
        if let value = offset { items.append(QueryItem("offset", String(value))) }
        if let value = includeTotal { items.append(QueryItem("include_total", value ? "true" : "false")) }
        return items
    }
}

// MARK: - Operations

extension IrdOperation {
    public static let domains_check = IrdOperation(method: .get, pathTemplate: "/domains/check", module: "domains", name: "check", security: .anonymousOrKey)
    public static let domains_info = IrdOperation(method: .get, pathTemplate: "/domains/info", module: "domains", name: "info", security: .keyOrJwt)
    public static let domains_preflight = IrdOperation(method: .get, pathTemplate: "/domains/preflight", module: "domains", name: "preflight", security: .keyOrJwt)
    public static let domains_dnsSnapshot = IrdOperation(method: .get, pathTemplate: "/domains/dns-snapshot", module: "domains", name: "dnsSnapshot", security: .keyOrJwt)
    public static let domains_search = IrdOperation(method: .get, pathTemplate: "/domains/search", module: "domains", name: "search", security: .keyOrJwt)
    public static let domains_searchDescriptions = IrdOperation(method: .post, pathTemplate: "/domains/search", module: "domains", name: "searchDescriptions", security: .keyOrJwt)
    public static let domains_example = IrdOperation(method: .get, pathTemplate: "/domains/example", module: "domains", name: "example", security: .anonymousOrKey)
    public static let domains_directory = IrdOperation(method: .get, pathTemplate: "/domains/directory", module: "domains", name: "directory", security: .keyOrJwt)
    public static let domains_directoryEntry = IrdOperation(method: .get, pathTemplate: "/domains/directory/{domain}", module: "domains", name: "directoryEntry", security: .keyOrJwt)

    static let domainsOperations: [IrdOperation] = [.domains_check, .domains_info, .domains_preflight, .domains_dnsSnapshot, .domains_search, .domains_searchDescriptions, .domains_example, .domains_directory, .domains_directoryEntry]
}

/// The `domains` operations (9).
public struct DomainsAPI: Sendable {
    let client: IrdClient

    /// Check domain availability
    /// Checks whether a domain can be registered (.ro only for now).
    /// `GET /domains/check` — 200
    /// Anonymous allowed.
    public func check(domain: String) async throws -> CheckResponse {
        try await client.request(.domains_check, query: [QueryItem("domain", domain)])
    }

    /// Domain information utilities
    /// Gathers public information about any domain: WHOIS record, live DNS records (NS/A/AAAA/MX/TXT/SOA), and — opt-in — subdomains observed in Certificate Transparency logs (crt.sh).
    /// `GET /domains/info` — 200
    public func info(domain: String, query: InfoQuery = InfoQuery()) async throws -> InfoResponse {
        try await client.request(.domains_info, query: [QueryItem("domain", domain)] + query.queryItems)
    }

    /// Route a domain to the right inbound operation
    /// Decides, before anything is enqueued or charged, which operation brings `domain` into your account: `adopt` (already sponsored by ird and the registrant email is an address you control — no registry operation needed), `trade-in` (already sp…
    /// `GET /domains/preflight` — 200
    public func preflight(domain: String) async throws -> PreflightResponse {
        try await client.request(.domains_preflight, query: [QueryItem("domain", domain)])
    }

    /// Faithful copy of a domain's live DNS
    /// Captures a point-in-time copy of a domain's live DNS straight from its authoritative nameservers (authentic TTLs; a whole-zone transfer is attempted first, falling back to probing the apex and common subdomain labels across A/AAAA/CNAME/MX/TXT/SRV/CAA plus NS/SOA at the apex).
    /// `GET /domains/dns-snapshot` — 200
    public func dnsSnapshot(domain: String, query: DnsSnapshotQuery = DnsSnapshotQuery()) async throws -> DnsSnapshotResponse {
        try await client.request(.domains_dnsSnapshot, query: [QueryItem("domain", domain)] + query.queryItems)
    }

    /// Suggest available domain names
    /// Generates new .ro domain name ideas from a free-form query — a domain, a phrase, or a description of what you're building — using an LLM, then checks each suggestion's availability.
    /// `GET /domains/search` — 200
    public func search(q: String, query: SearchQuery = SearchQuery()) async throws -> SearchResponse {
        try await client.request(.domains_search, query: [QueryItem("q", q)] + query.queryItems)
    }

    /// Suggest available domain names (long descriptions)
    /// Identical to GET /domains/search, but the query rides the request body — use this form for long project descriptions that do not fit a URL.
    /// `POST /domains/search` — 200
    public func searchDescriptions(body: SearchDescriptionsBody) async throws -> SearchResponse {
        try await client.request(.domains_searchDescriptions, body: body)
    }

    /// Example .ro domain
    /// Returns a generated example Romanian personal domain (a name or nickname under .ro), used as the rotating placeholder in the domain search box.
    /// `GET /domains/example` — 200
    /// Anonymous allowed.
    public func example() async throws -> DomainNameResponse {
        try await client.request(.domains_example)
    }

    /// Browse the .ro web directory
    /// Classified directory of .ro websites discovered by our crawler.
    /// `GET /domains/directory` — 200
    public func directory(query: DirectoryQuery = DirectoryQuery()) async throws -> DirectoryResponse {
        try await client.request(.domains_directory, query: query.queryItems)
    }

    /// Directory entry for a domain
    /// The classified directory record for one .ro domain. 404 when the domain has not been discovered and classified (yet). Requires an API key or an account JWT.
    /// `GET /domains/directory/{domain}` — 200
    public func directoryEntry(domain: String) async throws -> DirectoryEntry {
        try await client.request(.domains_directoryEntry, params: ["domain": domain])
    }
}

extension IrdClient {
    public var domains: DomainsAPI { DomainsAPI(client: self) }
}

static mirror of HEAD · about · clone: git clone https://ird.cod-sursa.ro/api-swift.git