yandex-webmaster-api 1.0.5

Rust client for the Yandex Webmaster API
Documentation
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
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
use chrono::{DateTime, NaiveDate, Utc};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use typed_builder::TypedBuilder;

// ============================================================================
// User
// ============================================================================

/// Response from the user endpoint
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct UserResponse {
    /// ID of the user. Required to call any Yandex Webmaster API resources.
    pub user_id: i64,
}

// ============================================================================
// Hosts (Sites)
// ============================================================================

/// Response containing a list of hosts
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct HostsResponse {
    /// List of hosts
    pub hosts: Vec<HostInfo>,
}

/// Site indexing status
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum HostDataStatus {
    /// The site isn't indexed yet.
    NotIndexed,
    /// The site data isn't uploaded to Yandex.Webmaster yet.
    NotLoaded,
    /// The site is indexed. The data is available in Yandex.Webmaster.
    Ok,
}

/// Information about a host
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct HostInfo {
    /// Site identifier
    pub host_id: String,
    /// ASCII-encoded site URL
    pub ascii_host_url: String,
    /// UTF-8 encoded site URL
    pub unicode_host_url: String,
    /// Ownership verification status
    pub verified: bool,
    /// Primary site address (if applicable)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub main_mirror: Option<Box<HostInfo>>,
}

/// Information about a host from `get_host` method
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct FullHostInfo {
    /// Site identifier
    pub host_id: String,
    /// ASCII-encoded site URL
    pub ascii_host_url: String,
    /// UTF-8 encoded site URL
    pub unicode_host_url: String,
    /// Ownership verification status
    pub verified: bool,
    /// Primary site address (if applicable)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub main_mirror: Option<Box<HostInfo>>,
    /// Information about the site (shown if the site is verified).
    pub host_data_status: Option<HostDataStatus>,
    /// The site name to display
    pub host_display_name: Option<String>,
}

/// Response from adding a new host
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct AddHostResponse {
    /// Assigned host ID
    pub host_id: String,
}

// ============================================================================
// Host Verification
// ============================================================================

/// Error description if the VERIFICATION_FAILED status is received.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct FailInfo {
    /// The reason why verification failed.
    pub message: String,
    /// Error description for users.
    pub reason: VerificationFailReason,
}
/// Host verification status
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct HostVerificationStatusResponse {
    /// Verification state
    pub verification_state: VerificationState,
    /// Verification type
    pub verification_type: VerificationType,
    /// Verification token (for DNS and HTML methods)
    pub verification_uin: String,
    /// The verification methods applied for the given site.
    pub applicable_verifiers: Vec<ExplicitVerificationType>,
    /// The time of the last check (if verification_state isn't NONE).
    pub latest_verification_time: Option<DateTime<Utc>>,
    /// Error description if the VERIFICATION_FAILED status is received.
    pub fail_info: Option<FailInfo>,
}

/// Host verification status
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct HostVerificationResponse {
    /// Verification state
    pub verification_state: VerificationState,
    /// Verification type
    pub verification_type: VerificationType,
    /// Verification token (for DNS and HTML methods)
    pub verification_uin: String,
    /// The verification methods applied for the given site.
    pub applicable_verifiers: Vec<ExplicitVerificationType>,
}

/// Verification state
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum VerificationState {
    /// Not verified
    None,
    /// Rights confirmed
    Verified,
    /// Verification pending
    InProgress,
    /// Rights not confirmed
    VerificationFailed,
    /// System error during verification
    InternalError,
}

/// Verification type
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum ExplicitVerificationType {
    /// DNS record verification
    Dns,
    /// Meta tag verification
    MetaTag,
    /// HTML file verification
    HtmlFile,
}

/// Verification type
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum VerificationType {
    /// Automatic rights verification (deprecated; only for *.narod.ru sites).
    Auto,
    /// Rights were delegated.
    Delegated,
    /// Rights verification via Yandex.Mail for Domains.
    Pdd,
    /// Placing a text file in the site's root directory.
    TxtFile,
    /// DNS record verification
    Dns,
    /// Meta tag verification
    MetaTag,
    /// HTML file verification
    HtmlFile,
}

/// Verification failure reason
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum VerificationFailReason {
    /// Rights delegation revoked
    DelegationCancelled,
    /// Missing DNS entry
    DnsRecordNotFound,
    /// Missing meta tag in homepage header
    MetaTagNotFound,
    /// Incorrect HTML file content
    WrongHtmlPageContent,
    /// Verification of site management rights via Yandex.Mail for Domain isn't allowed for this site.
    PddVerificationCancelled,
}

/// List of verified owners
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct OwnersResponse {
    /// List of owners
    pub users: Vec<Owner>,
}

/// Owner information
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct Owner {
    /// User login
    pub user_login: String,
    /// Confirmation code
    pub verification_uin: String,
    /// Rights verification method
    pub verification_type: VerificationType,
    /// Verification date
    #[serde(skip_serializing_if = "Option::is_none")]
    pub verification_date: Option<DateTime<Utc>>,
}

// ============================================================================
// Host Summary and Statistics
// ============================================================================

/// Site statistics summary
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct HostSummaryResponse {
    /// Site quality index
    #[serde(skip_serializing_if = "Option::is_none")]
    pub sqi: Option<f64>,
    /// Number of searchable pages
    #[serde(default)]
    pub searchable_pages_count: i64,
    /// Number of excluded pages
    #[serde(default)]
    pub excluded_pages_count: i64,
    /// Site problems grouped by severity
    #[serde(default)]
    pub site_problems: HashMap<SiteProblemSeverityEnum, i32>,
}

/// Excluded pages statistics by status
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct ExcludedPagesStatistics {
    /// Statistics by status
    pub statuses: HashMap<ApiExcludedUrlStatus, i64>,
}

/// Site quality index history request
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default, TypedBuilder)]
#[builder(field_defaults(default, setter(into)))]
pub struct SqiHistoryRequest {
    pub date_from: Option<DateTime<Utc>>,
    pub date_to: Option<DateTime<Utc>>,
}

/// Site quality index history
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct SqiHistoryResponse {
    /// History points
    pub points: Vec<SqiPoint>,
}

/// Single SQI history point
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct SqiPoint {
    /// Date
    pub date: DateTime<Utc>,
    /// SQI value
    pub value: f64,
}

// ============================================================================
// Search Queries
// ============================================================================

/// Query sorting order field
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum ApiQueryOrderField {
    /// Sort by total shows
    TotalShows,
    /// Sort by total clicks
    TotalClicks,
}

/// Query indicators
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Hash)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum ApiQueryIndicator {
    /// Total number of shows
    TotalShows,
    /// Total number of clicks
    TotalClicks,
    /// Average show position
    AvgShowPosition,
    /// Average click position
    AvgClickPosition,
}

/// Device type indicator
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Default)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum ApiDeviceTypeIndicator {
    /// All device types
    #[default]
    All,
    /// Desktop computers
    Desktop,
    /// Mobile phones and tablets
    MobileAndTablet,
    /// Mobile phones only
    Mobile,
    /// Tablets only
    Tablet,
}

/// Popular queries request parameters
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, TypedBuilder)]
pub struct PopularQueriesRequest {
    /// Indicator for sorting requests (required)
    pub order_by: ApiQueryOrderField,
    /// Indicators for displaying requests
    #[serde(skip_serializing_if = "Option::is_none")]
    #[builder(default, setter(into, strip_option))]
    pub query_indicator: Option<ApiQueryIndicator>,
    /// Device type indicator (default: ALL)
    #[serde(skip_serializing_if = "Option::is_none")]
    #[builder(default, setter(into, strip_option))]
    pub device_type_indicator: Option<ApiDeviceTypeIndicator>,
    /// Start date of the range
    #[serde(skip_serializing_if = "Option::is_none")]
    #[builder(default, setter(into, strip_option))]
    pub date_from: Option<NaiveDate>,
    /// End date of the range
    #[serde(skip_serializing_if = "Option::is_none")]
    #[builder(default, setter(into, strip_option))]
    pub date_to: Option<NaiveDate>,
    /// List offset (minimum: 0, default: 0)
    #[serde(skip_serializing_if = "Option::is_none")]
    #[builder(default, setter(into, strip_option))]
    pub offset: Option<i32>,
    /// Page size (1-500, default: 500)
    #[serde(skip_serializing_if = "Option::is_none")]
    #[builder(default, setter(into, strip_option))]
    pub limit: Option<i32>,
}

/// Popular search queries response
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct PopularQueriesResponse {
    /// List of queries
    pub queries: Vec<PopularQuery>,
    /// Start date of the range
    pub date_from: NaiveDate,
    /// End date of the range
    pub date_to: NaiveDate,
    /// Total number of search queries available
    pub count: i32,
}

/// Popular query information
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct PopularQuery {
    /// Query ID
    pub query_id: String,
    /// Query text
    pub query_text: String,
    /// Query indicators (e.g., TOTAL_SHOWS, TOTAL_CLICKS, etc.)
    pub indicators: std::collections::HashMap<ApiQueryIndicator, f64>,
}

/// Query analytics request parameters
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, TypedBuilder)]
pub struct QueryAnalyticsRequest {
    /// Indicators for displaying requests (can specify multiple)
    pub query_indicator: Vec<ApiQueryIndicator>,
    /// Device type indicator (default: ALL)
    #[serde(skip_serializing_if = "Option::is_none")]
    #[builder(default, setter(into, strip_option))]
    pub device_type_indicator: Option<ApiDeviceTypeIndicator>,
    /// Start date of the range
    #[serde(skip_serializing_if = "Option::is_none")]
    #[builder(default, setter(into, strip_option))]
    pub date_from: Option<DateTime<Utc>>,
    /// End date of the range
    #[serde(skip_serializing_if = "Option::is_none")]
    #[builder(default, setter(into, strip_option))]
    pub date_to: Option<DateTime<Utc>>,
}

/// Query analytics response
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct QueryAnalyticsResponse {
    /// Map of indicators to their history points
    pub indicators: std::collections::HashMap<ApiQueryIndicator, Vec<IndicatorPoint>>,
}

/// Single indicator history point
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct IndicatorPoint {
    /// Date
    pub date: DateTime<Utc>,
    /// Value
    pub value: f64,
}

/// Query history request parameters
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, TypedBuilder)]
pub struct QueryHistoryRequest {
    /// Indicators for displaying requests (can specify multiple)
    pub query_indicator: Vec<ApiQueryIndicator>,
    /// Device type indicator (default: ALL)
    #[serde(skip_serializing_if = "Option::is_none")]
    #[builder(default, setter(into, strip_option))]
    pub device_type_indicator: Option<ApiDeviceTypeIndicator>,
    /// Start date of the range
    #[serde(skip_serializing_if = "Option::is_none")]
    #[builder(default, setter(into, strip_option))]
    pub date_from: Option<NaiveDate>,
    /// End date of the range
    #[serde(skip_serializing_if = "Option::is_none")]
    #[builder(default, setter(into, strip_option))]
    pub date_to: Option<NaiveDate>,
}

/// Query history response
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct QueryHistoryResponse {
    /// Search query ID
    pub query_id: String,
    /// Search query text
    pub query_text: String,
    /// Map of indicators to their history points
    pub indicators: std::collections::HashMap<ApiQueryIndicator, Vec<IndicatorPoint>>,
}

// ============================================================================
// Sitemaps
// ============================================================================

/// Source of the Sitemap file
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum ApiSitemapSource {
    /// Sitemap is specified in the site's robots.txt file
    RobotsTxt,
    /// The user added the Sitemap in Yandex.Webmaster
    Webmaster,
    /// Sitemap found in another (index) Sitemap file
    IndexSitemap,
}

/// Type of Sitemap file
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum ApiSitemapType {
    /// Normal Sitemap file that contains the URLs of site pages
    Sitemap,
    /// The Sitemap index file that contains the URLs of other Sitemap files
    IndexSitemap,
}

/// Request parameters for getting sitemaps
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default, TypedBuilder)]
#[builder(field_defaults(default, setter(into)))]
pub struct GetSitemapsRequest {
    /// Parent sitemap ID
    #[serde(skip_serializing_if = "Option::is_none")]
    pub parent_id: Option<String>,
    /// Page size (1-100, default: 10)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i32>,
    /// Get sitemaps starting after this ID (not including it)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub from: Option<String>,
}

/// List of sitemaps
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct SitemapsResponse {
    /// Sitemaps
    pub sitemaps: Vec<SitemapInfo>,
}

/// Sitemap information
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct SitemapInfo {
    /// Sitemap ID
    pub sitemap_id: String,
    /// Sitemap URL
    pub sitemap_url: String,
    /// Last access date
    #[serde(skip_serializing_if = "Option::is_none")]
    pub last_access_date: Option<DateTime<Utc>>,
    /// Number of errors in the file
    pub errors_count: i32,
    /// Number of URLs in the file
    pub urls_count: i64,
    /// Number of child Sitemap files
    pub children_count: i32,
    /// Sources that led the robot to this file
    pub sources: Vec<ApiSitemapSource>,
    /// Type of the Sitemap file
    pub sitemap_type: ApiSitemapType,
}

/// Request parameters for getting user-added sitemaps
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default, TypedBuilder)]
#[builder(field_defaults(default, setter(into)))]
pub struct GetUserSitemapsRequest {
    /// Get files starting from the specified one (not including it, default: 0)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub offset: Option<i32>,
    /// Page size (1-100, default: 100)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i32>,
}

/// List of user-added sitemaps
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct UserSitemapsResponse {
    /// Sitemaps
    pub sitemaps: Vec<UserSitemapInfo>,
    /// Total number of Sitemap files added by the user
    pub count: i32,
}

/// User-added sitemap information
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct UserSitemapInfo {
    /// Sitemap ID
    pub sitemap_id: String,
    /// Sitemap URL
    pub sitemap_url: String,
    /// Date the file was added
    pub added_date: DateTime<Utc>,
}

/// Response from adding a sitemap
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct AddSitemapResponse {
    /// Assigned sitemap ID
    pub sitemap_id: String,
}

// ============================================================================
// Indexing
// ============================================================================

/// Indexing status by HTTP code
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Hash)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum IndexingStatusEnum {
    /// HTTP 2xx responses
    #[serde(rename = "HTTP_2XX")]
    Http2xx,
    /// HTTP 3xx responses
    #[serde(rename = "HTTP_3XX")]
    Http3xx,
    /// HTTP 4xx responses
    #[serde(rename = "HTTP_4XX")]
    Http4xx,
    /// HTTP 5xx responses
    #[serde(rename = "HTTP_5XX")]
    Http5xx,
    /// Other statuses
    Other,
}

/// Site problem severity
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Hash)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum SiteProblemSeverityEnum {
    /// Fatal problems
    Fatal,
    /// Critical problems
    Critical,
    /// Possible problems
    PossibleProblem,
    /// Recommendations
    Recommendation,
}

/// Excluded URL status
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Hash)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum ApiExcludedUrlStatus {
    /// No exclusion found - robot doesn't know about page or it was unavailable
    NothingFound,
    /// Could not connect to server when accessing site
    HostError,
    /// Page redirects to another page (target page is indexed)
    RedirectNotsearchable,
    /// HTTP error occurred when accessing page
    HttpError,
    /// Page indexed by canonical URL specified in rel="canonical"
    NotCanonical,
    /// Page belongs to secondary site mirror
    NotMainMirror,
    /// Robot couldn't get page content
    ParserError,
    /// Site indexing prohibited in robots.txt
    RobotsHostError,
    /// Page indexing prohibited in robots.txt
    RobotsUrlError,
    /// Page duplicates a site page already in search
    Duplicate,
    /// Page excluded after robot processed Clean-param directive
    CleanParams,
    /// Page excluded because robots meta tag has noindex value
    NoIndex,
    /// Forbidden by robots.txt (legacy)
    ForbiddenByRobotsTxt,
    /// URL not allowed (legacy)
    UrlNotAllowed,
    /// Contains noindex meta tag (legacy)
    ContainsNoindexMetaTag,
    /// Contains noindex X-Robots-Tag header (legacy)
    ContainsNoindexXRobotsTagHeader,
    /// Sitemap forbidden (legacy)
    SitemapForbidden,
    /// Sitemap not allowed (legacy)
    SitemapNotAllowed,
    /// Low quality - removed due to low quality
    LowQuality,
    /// Alternative duplicate (legacy)
    AlternativeDuplicate,
    /// User duplicate (legacy)
    UserDuplicate,
    /// Canonical duplicate (legacy)
    CanonicalDuplicate,
    /// Redirect duplicate (legacy)
    RedirectDuplicate,
    /// Moved permanently (legacy)
    MovedPermanently,
    /// Moved temporarily (legacy)
    MovedTemporarily,
    /// Malware detected (legacy)
    MalwareDetected,
    /// Phishing detected (legacy)
    PhishingDetected,
    /// Adult content (legacy)
    AdultContent,
    /// Other reason - robot doesn't have updated data
    Other,
}

/// Important URL change indicator
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Hash)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum ApiImportantUrlChangeIndicator {
    /// Indexing HTTP code
    IndexingHttpCode,
    /// Search status
    SearchStatus,
    /// Page title
    Title,
    /// Page description
    Description,
}

/// Indexing history request
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default, TypedBuilder)]
#[builder(field_defaults(default, setter(into)))]
pub struct IndexingHistoryRequest {
    /// Date from
    #[serde(skip_serializing_if = "Option::is_none")]
    pub date_from: Option<DateTime<Utc>>,
    /// Date to
    #[serde(skip_serializing_if = "Option::is_none")]
    pub date_to: Option<DateTime<Utc>>,
}

/// Indexing history response
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct IndexingHistoryResponse {
    /// History indicators by status
    pub indicators: HashMap<IndexingStatusEnum, Vec<IndexingHistoryPoint>>,
}

/// Indexing history point
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct IndexingHistoryPoint {
    /// Date
    pub date: DateTime<Utc>,
    /// Value
    pub value: f64,
}

/// Get indexing samples request
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default, TypedBuilder)]
#[builder(field_defaults(default, setter(into)))]
pub struct GetIndexingSamplesRequest {
    /// Offset for pagination
    #[serde(skip_serializing_if = "Option::is_none")]
    pub offset: Option<i32>,
    /// Limit for pagination
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i32>,
}

/// Indexing samples response
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct IndexingSamplesResponse {
    /// Sample URLs
    pub samples: Vec<IndexingSample>,
    /// Total count
    pub count: i32,
}

/// Indexing sample
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct IndexingSample {
    /// URL
    pub url: String,
    /// HTTP status code
    pub http_code: i32,
    /// Last access date
    pub access_date: DateTime<Utc>,
}

// ============================================================================
// Search URLs (Pages in Search)
// ============================================================================

/// Search event type
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Hash)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum ApiSearchEventEnum {
    /// Page appeared in search results
    AppearedInSearch,
    /// Page removed from search results
    RemovedFromSearch,
}

/// Search URLs history response
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct SearchUrlsHistoryResponse {
    /// History points
    pub history: Vec<SearchUrlsHistoryPoint>,
}

/// Search URLs history point
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct SearchUrlsHistoryPoint {
    /// Date and time when search output was updated
    pub date: DateTime<Utc>,
    /// Number of pages in search
    pub value: i64,
}

/// Get search URLs samples request
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default, TypedBuilder)]
#[builder(field_defaults(default, setter(into)))]
pub struct GetSearchUrlsSamplesRequest {
    /// Offset for pagination
    #[serde(skip_serializing_if = "Option::is_none")]
    pub offset: Option<i32>,
    /// Limit for pagination (1-100, default 50)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i32>,
}

/// Search URLs samples response
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct SearchUrlsSamplesResponse {
    /// Total number of available examples
    pub count: i32,
    /// Sample pages
    pub samples: Vec<SearchUrlsSample>,
}

/// Search URLs sample
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct SearchUrlsSample {
    /// Page URL
    pub url: String,
    /// Date of the page version in search
    pub last_access: DateTime<Utc>,
    /// Page heading
    pub title: String,
}

/// Search events history response
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct SearchEventsHistoryResponse {
    /// History indicators by event type
    pub indicators: HashMap<ApiSearchEventEnum, Vec<SearchUrlsHistoryPoint>>,
}

/// Get search events samples request
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default, TypedBuilder)]
#[builder(field_defaults(default, setter(into)))]
pub struct GetSearchEventsSamplesRequest {
    /// Offset for pagination
    #[serde(skip_serializing_if = "Option::is_none")]
    pub offset: Option<i32>,
    /// Limit for pagination (1-100, default 50)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i32>,
}

/// Search events samples response
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct SearchEventsSamplesResponse {
    /// Total number of available examples
    pub count: i32,
    /// Sample pages
    pub samples: Vec<SearchEventsSample>,
}

/// Search events sample
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct SearchEventsSample {
    /// Page URL
    pub url: String,
    /// Page heading
    pub title: String,
    /// Date when page appeared or was excluded
    pub event_date: DateTime<Utc>,
    /// Date when page was last crawled before appearing or being excluded
    pub last_access: DateTime<Utc>,
    /// The appearance or removal of the page
    pub event: ApiSearchEventEnum,
    /// Reason the page was excluded
    #[serde(skip_serializing_if = "Option::is_none")]
    pub excluded_url_status: Option<ApiExcludedUrlStatus>,
    /// Page's HTTP response code for HTTP_ERROR status
    #[serde(skip_serializing_if = "Option::is_none")]
    pub bad_http_status: Option<i32>,
    /// Another address of the page (redirect target, canonical, or duplicate)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub target_url: Option<String>,
}

// ============================================================================
// Recrawl (Reindexing)
// ============================================================================

/// Response from recrawl request
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct RecrawlResponse {
    /// Task ID
    pub task_id: String,
}

/// Get recrawl tasks request
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default, TypedBuilder)]
#[builder(field_defaults(default, setter(into)))]
pub struct GetRecrawlTasksRequest {
    /// Offset in the list
    #[serde(skip_serializing_if = "Option::is_none")]
    pub offset: Option<i32>,
    /// Page size (minimum 1, default 50)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i32>,
    /// Start of the date range
    #[serde(skip_serializing_if = "Option::is_none")]
    pub date_from: Option<DateTime<Utc>>,
    /// End of the date range
    #[serde(skip_serializing_if = "Option::is_none")]
    pub date_to: Option<DateTime<Utc>>,
}

/// Recrawl task list response
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct RecrawlTasksResponse {
    /// Tasks
    pub tasks: Vec<RecrawlTask>,
}

/// Recrawl task information
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct RecrawlTask {
    /// Task ID
    pub task_id: String,
    /// URL of the page sent for reindexing
    pub url: String,
    /// Date the reindexing request was created
    #[serde(skip_serializing_if = "Option::is_none")]
    pub added_time: Option<DateTime<Utc>>,
    /// Status of the reindexing request
    pub state: RecrawlTaskState,
}

/// Recrawl task state (reindexing request status)
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum RecrawlTaskState {
    /// Request is being processed
    InProgress,
    /// Robot crawled the URL
    Done,
    /// Robot failed to crawl the page
    Failed,
}

/// Recrawl quota response
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct RecrawlQuotaResponse {
    /// Daily quota
    pub daily_quota: i32,
    /// Remainder of daily quota
    pub quota_remainder: i32,
}

// ============================================================================
// Links
// ============================================================================

/// Internal link indicators
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Hash)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum ApiInternalLinksBrokenIndicator {
    /// The total number of known external links to the site
    SiteError,
    /// The page doesn't exist or is prohibited from indexing
    DisallowedByUser,
    /// Not supported by the main Search indexing robot
    UnsupportedByRobot,
}

/// Broken links request parameters
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default, TypedBuilder)]
#[builder(field_defaults(default, setter(into)))]
pub struct BrokenLinksRequest {
    /// The broken link indicator — the reason the link doesn't work (ApiInternalLinksBrokenIndicator). You can specify multiple indicators. If the indicator is omitted, the report will contain all link types.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub indicator: Option<Vec<ApiInternalLinksBrokenIndicator>>,
    /// List offset (minimum: 0, default: 0)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub offset: Option<i32>,
    /// Page size (1-500, default: 500)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i32>,
}

/// Broken internal links samples
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct BrokenLinksResponse {
    /// The number of example links available
    pub count: i32,
    /// The URL of the page that contains the link to the site
    pub links: Vec<BrokenLink>,
}

/// Broken link information
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct BrokenLink {
    /// Source URL
    pub source_url: String,
    /// Destination URL
    pub destination_url: String,
    /// The date when the link was detected
    pub discovery_date: NaiveDate,
    /// The date when the robot last visited the target page
    pub source_last_access_date: NaiveDate,
}

/// Broken link history request
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default, TypedBuilder)]
#[builder(field_defaults(default, setter(into)))]
pub struct BrokenLinkHistoryRequest {
    /// Date from
    #[serde(skip_serializing_if = "Option::is_none")]
    pub date_from: Option<DateTime<Utc>>,
    /// Date to
    #[serde(skip_serializing_if = "Option::is_none")]
    pub date_to: Option<DateTime<Utc>>,
}

/// Broken link history point
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct BrokenLinkHistoryPoint {
    /// Date
    pub date: DateTime<Utc>,
    /// Value
    pub value: f64,
}

/// Broken link history response
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct BrokenLinkHistoryResponse {
    /// The reason the link doesn't work
    pub indicators: HashMap<ApiInternalLinksBrokenIndicator, Vec<BrokenLinkHistoryPoint>>,
}

/// External links request parameter
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default, TypedBuilder)]
#[builder(field_defaults(default, setter(into)))]
pub struct ExternalLinksRequest {
    /// List offset (minimum: 0, default: 0)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub offset: Option<i32>,
    /// Page size (1-500, default: 500)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i32>,
}

/// External backlinks samples
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct ExternalLinksResponse {
    /// The number of example links available
    pub count: i32,
    /// Samples
    pub links: Vec<ExternalLink>,
}

/// External link information
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct ExternalLink {
    /// Source URL
    pub source_url: String,
    /// Destination URL
    pub destination_url: String,
    /// The date when the link was detected
    pub discovery_date: NaiveDate,
    /// The date when the robot last visited the target page
    pub source_last_access_date: NaiveDate,
}

/// Indicators of external links
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Hash)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum ApiExternalLinksIndicator {
    /// The total number of known external links to the host
    LinksTotalCount,
}

/// Indexing history response
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct ExternalLinksHistoryResponse {
    /// History indicators by status
    pub indicators: HashMap<ApiExternalLinksIndicator, Vec<ExternalLinksHistoryPoint>>,
}

/// Indexing history point
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct ExternalLinksHistoryPoint {
    /// Date
    pub date: DateTime<Utc>,
    /// Value
    pub value: f64,
}

// ============================================================================
// Diagnostics
// ============================================================================

/// Site problem type
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Hash)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum ApiSiteProblemTypeEnum {
    // FATAL
    /// Robots couldn't visit the site (server settings or high load)
    ConnectFailed,
    /// Site prohibited for indexing in robots.txt
    DisallowedInRobots,
    /// Failed to connect to server due to DNS error
    DnsError,
    /// Site's home page returns an error
    MainPageError,
    /// Security threats or issues detected
    Threats,

    // CRITICAL
    /// Some pages with GET parameters duplicate content of other pages
    InsignificantCgiParameter,
    /// Slow server response
    SlowAvgResponseTime,
    /// Invalid SSL certificate settings
    SslCertificateError,
    /// Some pages respond with 4xx HTTP code for an hour
    #[serde(rename = "URL_ALERT_4XX")]
    UrlAlert4xx,
    /// Some pages respond with 5xx HTTP code for an hour
    #[serde(rename = "URL_ALERT_5XX")]
    UrlAlert5xx,

    // POSSIBLE_PROBLEM
    /// Useful pages found that are closed from indexing
    DisallowedUrlsAlert,
    /// Many pages missing Description meta tag
    DocumentsMissingDescription,
    /// Title element missing on many pages
    DocumentsMissingTitle,
    /// Some pages have identical title and Description
    DuplicateContentAttrs,
    /// Some pages contain identical content
    DuplicatePages,
    /// Errors in robots.txt file
    ErrorInRobotsTxt,
    /// Errors found in Sitemap file
    ErrorsInSitemaps,
    /// Favicon file unavailable on site
    FaviconError,
    /// Main mirror doesn't use HTTPS protocol
    MainMirrorIsNotHttps,
    /// Main page redirects to another site
    MainPageRedirects,
    /// No Yandex.Metrica counter linked to site
    NoMetrikaCounterBinding,
    /// Site crawling using Yandex.Metrica counters not enabled
    NoMetrikaCounterCrawlEnabled,
    /// robots.txt file not found
    NoRobotsTxt,
    /// No Sitemap files used by robot
    NoSitemaps,
    /// Sitemap files haven't been updated for a long time
    NoSitemapModifications,
    /// Robot failed to index marked videos on site
    NonWorkingVideo,
    /// Display of non-existent files and pages configured incorrectly
    #[serde(rename = "SOFT_404")]
    Soft404,
    /// Site subdomains found in search results
    TooManyDomainsOnSearch,
    /// User agreement for video display added to Webmaster was rejected
    VideohostOfferFailed,
    /// User agreement for video display missing for site
    VideohostOfferIsNeeded,
    /// Special agreement with Yandex needed for site cooperation
    VideohostOfferNeedPaper,

    // RECOMMENDATION
    /// Add favicon in SVG format or 120×120 pixels size
    BigFaviconAbsent,
    /// Favicon file not found - robot couldn't load image for browser tab
    FaviconProblem,
    /// Yandex.Metrica counter error
    NoMetrikaCounter,
    /// Site region not set
    NoRegions,
    /// Site not registered in Yandex.Directory
    NotInSprav,
    /// Site not optimized for mobile devices
    NotMobileFriendly,
    /// Yandex.Vygoda not connected to site
    VygodaPossibleActivation,
}

/// Site problem state
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Hash)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum ApiSiteProblemState {
    /// Present on the site
    Present,
    /// Missing
    Absent,
    /// Not enough data to determine if there are issues
    Undefined,
}

/// Site diagnostics response
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct DiagnosticsResponse {
    /// Problems by type
    pub problems: HashMap<ApiSiteProblemTypeEnum, SiteProblemInfo>,
}

/// Site problem information
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct SiteProblemInfo {
    /// Issue type (severity)
    pub severity: SiteProblemSeverityEnum,
    /// State of the issue
    pub state: ApiSiteProblemState,
    /// Date the issue status was last changed
    pub last_state_update: Option<DateTime<Utc>>,
}

// ============================================================================
// Important URLs
// ============================================================================

/// Important URLs response
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct ImportantUrlsResponse {
    /// URLs
    pub urls: Vec<ImportantUrl>,
}

/// Important URL information
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct ImportantUrl {
    /// Site page URL
    pub url: String,
    /// Date and time the page status information was updated
    #[serde(skip_serializing_if = "Option::is_none")]
    pub update_date: Option<DateTime<Utc>>,
    /// Indicator of changes from previous check
    #[serde(default)]
    pub change_indicators: Vec<ApiImportantUrlChangeIndicator>,
    /// Information about page indexing by the robot
    #[serde(skip_serializing_if = "Option::is_none")]
    pub indexing_status: Option<IndexingStatus>,
    /// State of the page in search results
    #[serde(skip_serializing_if = "Option::is_none")]
    pub search_status: Option<SearchStatus>,
}

/// Page indexing status
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct IndexingStatus {
    /// Generalized status of the HTTP code
    pub status: IndexingStatusEnum,
    /// HTTP code
    #[serde(skip_serializing_if = "Option::is_none")]
    pub http_code: Option<i32>,
    /// Date the page was crawled
    pub access_date: DateTime<Utc>,
}

/// Page search status
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct SearchStatus {
    /// Page heading
    pub title: String,
    /// Description meta tag content
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
    /// Date when page was last crawled before appearing or being excluded
    pub last_access: DateTime<Utc>,
    /// Reason the page was excluded
    #[serde(skip_serializing_if = "Option::is_none")]
    pub excluded_url_status: Option<ApiExcludedUrlStatus>,
    /// Page's HTTP response code for HTTP_ERROR status
    #[serde(skip_serializing_if = "Option::is_none")]
    pub bad_http_status: Option<i32>,
    /// Whether page is present in search results
    pub searchable: bool,
    /// Another address of the page (redirect target, canonical, or duplicate)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub target_url: Option<String>,
}

/// Important URL history response
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct ImportantUrlHistoryResponse {
    /// History of changes to the page
    pub history: Vec<ImportantUrl>,
}