data-for-seo 0.2.0

Client library for the DataForSEO API v3 (SERP, Keywords Data, Labs, Backlinks, OnPage, and more)
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
use crate::entity::{
    OnPageDataApiContentParsing, OnPageDataApiDuplicateContent, OnPageDataApiDuplicateTags,
    OnPageDataApiError, OnPageDataApiIdList, OnPageDataApiInstantPages,
    OnPageDataApiKeywordDensity, OnPageDataApiLighthouseTaskGet, OnPageDataApiLighthouseTasksReady,
    OnPageDataApiLinks, OnPageDataApiMicrodata, OnPageDataApiNonIndexable, OnPageDataApiPage,
    OnPageDataApiPageScreensShot, OnPageDataApiRawHtml, OnPageDataApiRedirectChains,
    OnPageDataApiResources, OnPageDataApiSummary, OnPageDataApiTasksReady, OnPageDataApiWaterfall,
};
use crate::{DataForSeoApiResponse, DataForSeoClient};
use serde::{Deserialize, Serialize};
use serde_json::Value;

/// OnPage API — on-page SEO audit and website crawling.
/// See <https://docs.dataforseo.com/v3/on_page/overview/>.
pub struct OnPageApi<'a> {
    client: &'a DataForSeoClient,
}

impl DataForSeoClient {
    /// Returns the OnPage API endpoint group.
    pub fn on_page(&self) -> OnPageApi<'_> {
        OnPageApi { client: self }
    }
}

impl OnPageApi<'_> {
    /// Sets a crawling task for the target website.
    /// See <https://docs.dataforseo.com/v3/on_page/task_post/>.
    pub async fn task_post(&self, data: Vec<OnPageApiTaskPost>) -> DataForSeoApiResponse<Value> {
        self.client.http_post("/v3/on_page/task_post", &data).await
    }

    /// Returns the list of completed crawling tasks.
    /// See <https://docs.dataforseo.com/v3/on_page/tasks_ready/>.
    pub async fn tasks_ready(&self) -> DataForSeoApiResponse<OnPageDataApiTasksReady> {
        self.client.http_get("/v3/on_page/tasks_ready").await
    }

    /// Stops an active crawling session.
    /// See <https://docs.dataforseo.com/v3/on_page/force_stop/>.
    pub async fn force_stop(
        &self,
        data: Vec<OnPageApiForceStopPost>,
    ) -> DataForSeoApiResponse<Value> {
        self.client.http_post("/v3/on_page/force_stop", &data).await
    }

    /// Returns a summary of the crawling results for a task.
    /// See <https://docs.dataforseo.com/v3/on_page/summary/>.
    pub async fn summary(&self, id: &str) -> DataForSeoApiResponse<OnPageDataApiSummary> {
        self.client
            .http_get(format!("/v3/on_page/summary/{id}").as_str())
            .await
    }

    /// Returns the crawled pages of a task.
    /// See <https://docs.dataforseo.com/v3/on_page/pages/>.
    pub async fn pages(
        &self,
        data: Vec<OnPageApiPagesPost>,
    ) -> DataForSeoApiResponse<OnPageDataApiPage> {
        self.client.http_post("/v3/on_page/pages", &data).await
    }

    /// Returns the pages on which a given resource appears.
    /// See <https://docs.dataforseo.com/v3/on_page/pages_by_resource/>.
    pub async fn pages_by_resource(
        &self,
        data: Vec<OnPageApiPagesByResourcePost>,
    ) -> DataForSeoApiResponse<OnPageDataApiPage> {
        self.client
            .http_post("/v3/on_page/pages_by_resource", &data)
            .await
    }

    /// Returns the resources (images, scripts, stylesheets, ...) found during crawling.
    /// See <https://docs.dataforseo.com/v3/on_page/resources/>.
    pub async fn resources(
        &self,
        data: Vec<OnPageApiResourcesPost>,
    ) -> DataForSeoApiResponse<OnPageDataApiResources> {
        self.client.http_post("/v3/on_page/resources", &data).await
    }

    /// Returns pages that share duplicate title or description tags.
    /// See <https://docs.dataforseo.com/v3/on_page/duplicate_tags/>.
    pub async fn duplicate_tags(
        &self,
        data: Vec<OnPageApiDuplicateTagsPost>,
    ) -> DataForSeoApiResponse<OnPageDataApiDuplicateTags> {
        self.client
            .http_post("/v3/on_page/duplicate_tags", &data)
            .await
    }

    /// Returns pages with content duplicating a given page.
    /// See <https://docs.dataforseo.com/v3/on_page/duplicate_content/>.
    pub async fn duplicate_content(
        &self,
        data: Vec<OnPageApiDuplicateContentPost>,
    ) -> DataForSeoApiResponse<OnPageDataApiDuplicateContent> {
        self.client
            .http_post("/v3/on_page/duplicate_content", &data)
            .await
    }

    /// Returns the internal and external links discovered during crawling.
    /// See <https://docs.dataforseo.com/v3/on_page/links/>.
    pub async fn links(
        &self,
        data: Vec<OnPageApiLinksPost>,
    ) -> DataForSeoApiResponse<OnPageDataApiLinks> {
        self.client.http_post("/v3/on_page/links", &data).await
    }

    /// Returns redirect chains and loops found during crawling.
    /// See <https://docs.dataforseo.com/v3/on_page/redirect_chains/>.
    pub async fn redirect_chains(
        &self,
        data: Vec<OnPageApiRedirectChainsPost>,
    ) -> DataForSeoApiResponse<OnPageDataApiRedirectChains> {
        self.client
            .http_post("/v3/on_page/redirect_chains", &data)
            .await
    }

    /// Returns pages that are not available for indexing.
    /// See <https://docs.dataforseo.com/v3/on_page/non_indexable/>.
    pub async fn non_indexable(
        &self,
        data: Vec<OnPageApiNonIndexablePost>,
    ) -> DataForSeoApiResponse<OnPageDataApiNonIndexable> {
        self.client
            .http_post("/v3/on_page/non_indexable", &data)
            .await
    }

    /// Returns the loading sequence of resources for a page.
    /// See <https://docs.dataforseo.com/v3/on_page/waterfall/>.
    pub async fn waterfall(
        &self,
        data: Vec<OnPageApiWaterfallPost>,
    ) -> DataForSeoApiResponse<OnPageDataApiWaterfall> {
        self.client.http_post("/v3/on_page/waterfall", &data).await
    }

    /// Returns keyword density metrics for the crawled content.
    /// See <https://docs.dataforseo.com/v3/on_page/keyword_density/>.
    pub async fn keyword_density(
        &self,
        data: Vec<OnPageApiKeywordDensityPost>,
    ) -> DataForSeoApiResponse<OnPageDataApiKeywordDensity> {
        self.client
            .http_post("/v3/on_page/keyword_density", &data)
            .await
    }

    /// Validates the structured markup (microdata) of a page.
    /// See <https://docs.dataforseo.com/v3/on_page/microdata/>.
    pub async fn microdata(
        &self,
        data: Vec<OnPageApiMicrodataPost>,
    ) -> DataForSeoApiResponse<OnPageDataApiMicrodata> {
        self.client.http_post("/v3/on_page/microdata", &data).await
    }

    /// Returns the raw HTML stored for a crawled page.
    /// See <https://docs.dataforseo.com/v3/on_page/raw_html/>.
    pub async fn raw_html(
        &self,
        data: Vec<OnPageApiRawHtmlPost>,
    ) -> DataForSeoApiResponse<OnPageDataApiRawHtml> {
        self.client.http_post("/v3/on_page/raw_html", &data).await
    }

    /// Captures a screenshot of a page.
    /// See <https://docs.dataforseo.com/v3/on_page/page_screenshot/>.
    pub async fn page_screenshot(
        &self,
        data: Vec<OnPageApiPageScreenshotPost>,
    ) -> DataForSeoApiResponse<OnPageDataApiPageScreensShot> {
        self.client
            .http_post("/v3/on_page/page_screenshot", &data)
            .await
    }

    /// Parses the structured content of a crawled page.
    /// See <https://docs.dataforseo.com/v3/on_page/content_parsing/>.
    pub async fn content_parsing(
        &self,
        data: Vec<OnPageApiContentParsingPost>,
    ) -> DataForSeoApiResponse<OnPageDataApiContentParsing> {
        self.client
            .http_post("/v3/on_page/content_parsing", &data)
            .await
    }

    /// Parses the structured content of a page in real time.
    /// See <https://docs.dataforseo.com/v3/on_page/content_parsing/live/>.
    pub async fn content_parsing_live(
        &self,
        data: Vec<OnPageApiContentParsingLivePost>,
    ) -> DataForSeoApiResponse<OnPageDataApiContentParsing> {
        self.client
            .http_post("/v3/on_page/content_parsing/live", &data)
            .await
    }

    /// Crawls and returns on-page data for a single page in real time.
    /// See <https://docs.dataforseo.com/v3/on_page/instant_pages/>.
    pub async fn instant_pages(
        &self,
        data: Vec<OnPageApiInstantPagesPost>,
    ) -> DataForSeoApiResponse<OnPageDataApiInstantPages> {
        self.client
            .http_post("/v3/on_page/instant_pages", &data)
            .await
    }

    /// Returns the list of task IDs created within a datetime range.
    /// See <https://docs.dataforseo.com/v3/on_page/id_list/>.
    pub async fn id_list(
        &self,
        data: Vec<OnPageApiIdListPost>,
    ) -> DataForSeoApiResponse<OnPageDataApiIdList> {
        self.client.http_post("/v3/on_page/id_list", &data).await
    }

    /// Returns OnPage API errors from the past 7 days (free of charge).
    /// See <https://docs.dataforseo.com/v3/on_page/errors/>.
    pub async fn errors(
        &self,
        data: Vec<OnPageApiErrorsPost>,
    ) -> DataForSeoApiResponse<OnPageDataApiError> {
        self.client.http_post("/v3/on_page/errors", &data).await
    }

    /// Returns the full list of filters available for OnPage endpoints (free of charge).
    /// See <https://docs.dataforseo.com/v3/on_page/filters_and_thresholds/>.
    pub async fn available_filters(&self) -> DataForSeoApiResponse<Value> {
        self.client.http_get("/v3/on_page/available_filters").await
    }

    /// Sets a Lighthouse audit task for a page.
    /// See <https://docs.dataforseo.com/v3/on_page/lighthouse/task_post/>.
    pub async fn lighthouse_task_post(
        &self,
        data: Vec<OnPageApiLighthouseTaskPost>,
    ) -> DataForSeoApiResponse<Value> {
        self.client
            .http_post("/v3/on_page/lighthouse/task_post", &data)
            .await
    }

    /// Returns the list of completed Lighthouse audit tasks.
    /// See <https://docs.dataforseo.com/v3/on_page/lighthouse/tasks_ready/>.
    pub async fn lighthouse_tasks_ready(
        &self,
    ) -> DataForSeoApiResponse<OnPageDataApiLighthouseTasksReady> {
        self.client
            .http_get("/v3/on_page/lighthouse/tasks_ready")
            .await
    }

    /// Returns the result of a completed Lighthouse audit task.
    /// See <https://docs.dataforseo.com/v3/on_page/lighthouse/task_get/>.
    pub async fn lighthouse_task_get(
        &self,
        id: &str,
    ) -> DataForSeoApiResponse<OnPageDataApiLighthouseTaskGet> {
        self.client
            .http_get(format!("/v3/on_page/lighthouse/task_get/json/{id}").as_str())
            .await
    }

    /// Runs a Lighthouse audit for a page in real time.
    /// See <https://docs.dataforseo.com/v3/on_page/lighthouse/live/>.
    pub async fn lighthouse_live(
        &self,
        data: Vec<OnPageApiLighthouseLivePost>,
    ) -> DataForSeoApiResponse<OnPageDataApiLighthouseTaskGet> {
        self.client
            .http_post("/v3/on_page/lighthouse/live/json", &data)
            .await
    }
}

/// Request for [`OnPageApi::task_post`].
/// See <https://docs.dataforseo.com/v3/on_page/task_post/>.
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
pub struct OnPageApiTaskPost {
    /// Domain to crawl, without protocol or `www` (e.g. "example.com").
    pub target: String,
    /// Maximum number of pages to crawl.
    pub max_crawl_pages: i32,
    /// First URL to crawl; defaults to the domain's home page.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub start_url: Option<String>,
    /// Run sitewide checks even when only a single page is crawled.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub force_sitewide_checks: Option<bool>,
    /// URLs to crawl before the rest of the site (max 20).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub priority_urls: Option<Vec<String>>,
    /// Maximum crawl depth, counted in clicks from the start page.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub max_crawl_depth: Option<i32>,
    /// Delay between page requests, in milliseconds.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub crawl_delay: Option<i32>,
    /// Store the raw HTML of crawled pages for later retrieval.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub store_raw_html: Option<bool>,
    /// Parse page content so it can be retrieved via the content endpoints.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub enable_content_parsing: Option<bool>,
    /// Accept cookies while crawling.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub support_cookies: Option<bool>,
    /// Value of the Accept-Language header sent while crawling.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub accept_language: Option<String>,
    /// Custom robots.txt content to apply during the crawl.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub custom_robots_txt: Option<String>,
    /// How custom robots.txt combines with the site's: "merge" or "override".
    #[serde(skip_serializing_if = "Option::is_none")]
    pub robots_txt_merge_mode: Option<String>,
    /// Custom User-Agent header sent while crawling.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub custom_user_agent: Option<String>,
    /// Device preset for rendering: "desktop", "mobile", or "tablet".
    #[serde(skip_serializing_if = "Option::is_none")]
    pub browser_preset: Option<String>,
    /// Viewport width used for rendering, in pixels.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub browser_screen_width: Option<i32>,
    /// Viewport height used for rendering, in pixels.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub browser_screen_height: Option<i32>,
    /// Device pixel ratio used for rendering.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub browser_screen_scale_factor: Option<f64>,
    /// Crawl following the site's XML sitemap.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub respect_sitemap: Option<bool>,
    /// URL of a custom sitemap to crawl.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub custom_sitemap: Option<String>,
    /// Restrict the crawl to URLs listed in the sitemap.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub crawl_sitemap_only: Option<bool>,
    /// Load page resources (images, scripts, stylesheets) while crawling.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub load_resources: Option<bool>,
    /// Check whether the www and non-www versions redirect consistently.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub enable_www_redirect_check: Option<bool>,
    /// Execute page JavaScript while crawling (incurs extra cost).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub enable_javascript: Option<bool>,
    /// Allow XMLHttpRequest calls while rendering the page.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub enable_xhr: Option<bool>,
    /// Emulate full browser rendering to measure Core Web Vitals.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub enable_browser_rendering: Option<bool>,
    /// Hide cookie-consent popups before capturing the page.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub disable_cookie_popup: Option<bool>,
    /// Custom JavaScript to execute on each crawled page.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub custom_js: Option<String>,
    /// Validate structured microdata markup on crawled pages.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub validate_micromarkup: Option<bool>,
    /// Crawl subdomains of the target domain.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub allow_subdomains: Option<bool>,
    /// Subdomains to crawl (used when subdomains are otherwise excluded).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub allowed_subdomains: Option<Vec<String>>,
    /// Subdomains to exclude from the crawl.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub disallowed_subdomains: Option<Vec<String>>,
    /// Check spelling on crawled pages using the Hunspell library.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub check_spell: Option<bool>,
    /// Hunspell language code used for spell checking.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub check_spell_language: Option<String>,
    /// Words to ignore during spell checking (max 1000).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub check_spell_exceptions: Option<Vec<String>>,
    /// Compute keyword density for crawled pages.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub calculate_keyword_density: Option<bool>,
    /// Custom threshold values for the checks in OnPage responses.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub checks_threshold: Option<Value>,
    /// Sitewide checks to skip during the crawl.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub disable_sitewide_checks: Option<Vec<String>>,
    /// Per-page checks to skip during the crawl.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub disable_page_checks: Option<Vec<String>>,
    /// Retry using a different proxy pool if the first attempt fails.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub switch_pool: Option<bool>,
    /// Return partial results even if the crawl times out.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub return_despite_timeout: Option<bool>,
    /// User-defined task identifier (max 255 characters).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tag: Option<String>,
    /// URL notified by GET when the task completes.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub pingback_url: Option<String>,
}

impl OnPageApiTaskPost {
    /// Creates a task request for `target`, crawling up to `max_crawl_pages` pages.
    pub fn new(target: String, max_crawl_pages: i32) -> Self {
        OnPageApiTaskPost {
            target,
            max_crawl_pages,
            ..OnPageApiTaskPost::default()
        }
    }
}

/// Request for [`OnPageApi::pages`].
/// See <https://docs.dataforseo.com/v3/on_page/pages/>.
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
pub struct OnPageApiPagesPost {
    /// Task identifier returned by the Task POST endpoint.
    pub id: String,
    /// Maximum number of pages to return (default 100, max 1000).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i32>,
    /// Offset into the results array (default 0).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub offset: Option<i32>,
    /// Result filtering rules (max 8).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub filters: Option<Vec<Vec<String>>>,
    /// Sorting rules, each as "field,asc" or "field,desc" (max 3).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub order_by: Option<Vec<String>>,
    /// Pagination token returned by a previous response.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub search_after_token: Option<String>,
    /// User-defined task identifier (max 255 characters).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tag: Option<String>,
}

impl OnPageApiPagesPost {
    /// Creates a pages request for the given task `id`.
    pub fn new(id: String) -> Self {
        OnPageApiPagesPost {
            id,
            ..OnPageApiPagesPost::default()
        }
    }
}

/// Request for [`OnPageApi::pages_by_resource`].
/// See <https://docs.dataforseo.com/v3/on_page/pages_by_resource/>.
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
pub struct OnPageApiPagesByResourcePost {
    /// Task identifier returned by the Task POST endpoint.
    pub id: String,
    /// Resource URL, obtained from the Resources endpoint.
    pub url: String,
    /// Maximum number of pages to return (default 100, max 1000).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i32>,
    /// Offset into the results array (default 0).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub offset: Option<i32>,
    /// Result filtering rules (max 8).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub filters: Option<Vec<Vec<String>>>,
    /// Sorting rules, each as "field,asc" or "field,desc" (max 3).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub order_by: Option<Vec<String>>,
    /// User-defined task identifier (max 255 characters).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tag: Option<String>,
}

impl OnPageApiPagesByResourcePost {
    /// Creates a request for pages on which the resource `url` appears, for task `id`.
    pub fn new(id: String, url: String) -> Self {
        OnPageApiPagesByResourcePost {
            id,
            url,
            ..OnPageApiPagesByResourcePost::default()
        }
    }
}

/// Request for [`OnPageApi::resources`].
/// See <https://docs.dataforseo.com/v3/on_page/resources/>.
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
pub struct OnPageApiResourcesPost {
    /// Task identifier returned by the Task POST endpoint.
    pub id: String,
    /// Restrict results to resources found on this page URL.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub url: Option<String>,
    /// Maximum number of resources to return (default 100, max 1000).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i32>,
    /// Offset into the results array (default 0).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub offset: Option<i32>,
    /// Result filtering rules applied to resources (max 8).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub filters: Option<Vec<Value>>,
    /// Filtering rules applied to the pages that reference each resource.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub relevant_pages_filters: Option<Vec<Value>>,
    /// Sorting rules, each as "field,asc" or "field,desc" (max 3).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub order_by: Option<Vec<String>>,
    /// Pagination token returned by a previous response.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub search_after_token: Option<String>,
    /// User-defined task identifier (max 255 characters).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tag: Option<String>,
}

impl OnPageApiResourcesPost {
    /// Creates a resources request for the given task `id`.
    pub fn new(id: String) -> Self {
        OnPageApiResourcesPost {
            id,
            ..OnPageApiResourcesPost::default()
        }
    }
}

/// Request for [`OnPageApi::duplicate_tags`].
/// See <https://docs.dataforseo.com/v3/on_page/duplicate_tags/>.
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
pub struct OnPageApiDuplicateTagsPost {
    /// Task identifier returned by the Task POST endpoint.
    pub id: String,
    /// `duplicate_title` or `duplicate_description`.
    #[serde(rename = "type")]
    pub duplicate_type: String,
    /// Restrict results to a specific title or description value.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub accumulator: Option<String>,
    /// Maximum number of pages to return (default 100, max 1000).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i32>,
    /// Offset into the results array (default 0).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub offset: Option<i32>,
    /// User-defined task identifier (max 255 characters).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tag: Option<String>,
}

impl OnPageApiDuplicateTagsPost {
    /// Creates a duplicate-tags request for task `id` and the given `duplicate_type`.
    pub fn new(id: String, duplicate_type: String) -> Self {
        OnPageApiDuplicateTagsPost {
            id,
            duplicate_type,
            ..OnPageApiDuplicateTagsPost::default()
        }
    }
}

/// Request for [`OnPageApi::duplicate_content`].
/// See <https://docs.dataforseo.com/v3/on_page/duplicate_content/>.
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
pub struct OnPageApiDuplicateContentPost {
    /// Task identifier returned by the Task POST endpoint.
    pub id: String,
    /// Page URL to compare other pages against.
    pub url: String,
    /// Minimum content similarity to include, from 0 to 10 (default 6).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub similarity: Option<i32>,
    /// Maximum number of pages to return (default 100, max 1000).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i32>,
    /// Offset into the results array (default 0).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub offset: Option<i32>,
    /// User-defined task identifier (max 255 characters).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tag: Option<String>,
}

impl OnPageApiDuplicateContentPost {
    /// Creates a duplicate-content request for task `id`, comparing against `url`.
    pub fn new(id: String, url: String) -> Self {
        OnPageApiDuplicateContentPost {
            id,
            url,
            ..OnPageApiDuplicateContentPost::default()
        }
    }
}

/// Request for [`OnPageApi::links`].
/// See <https://docs.dataforseo.com/v3/on_page/links/>.
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
pub struct OnPageApiLinksPost {
    /// Task identifier returned by the Task POST endpoint.
    pub id: String,
    /// Restrict results to links originating from this page URL.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub page_from: Option<String>,
    /// Restrict results to links pointing to this page URL.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub page_to: Option<String>,
    /// Maximum number of links to return (default 100, max 1000).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i32>,
    /// Offset into the results array (default 0).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub offset: Option<i32>,
    /// Result filtering rules (max 8).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub filters: Option<Vec<Value>>,
    /// Pagination token returned by a previous response.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub search_after_token: Option<String>,
    /// User-defined task identifier (max 255 characters).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tag: Option<String>,
}

impl OnPageApiLinksPost {
    /// Creates a links request for the given task `id`.
    pub fn new(id: String) -> Self {
        OnPageApiLinksPost {
            id,
            ..OnPageApiLinksPost::default()
        }
    }
}

/// Request for [`OnPageApi::redirect_chains`].
/// See <https://docs.dataforseo.com/v3/on_page/redirect_chains/>.
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
pub struct OnPageApiRedirectChainsPost {
    /// Task identifier returned by the Task POST endpoint.
    pub id: String,
    /// Restrict results to redirect chains starting at this URL.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub url: Option<String>,
    /// Maximum number of chains to return (default 100, max 1000).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i32>,
    /// Offset into the results array (default 0).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub offset: Option<i32>,
    /// Result filtering rules; only `is_redirect_loop` is supported.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub filters: Option<Vec<Value>>,
    /// User-defined task identifier (max 255 characters).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tag: Option<String>,
}

impl OnPageApiRedirectChainsPost {
    /// Creates a redirect-chains request for the given task `id`.
    pub fn new(id: String) -> Self {
        OnPageApiRedirectChainsPost {
            id,
            ..OnPageApiRedirectChainsPost::default()
        }
    }
}

/// Request for [`OnPageApi::non_indexable`].
/// See <https://docs.dataforseo.com/v3/on_page/non_indexable/>.
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
pub struct OnPageApiNonIndexablePost {
    /// Task identifier returned by the Task POST endpoint.
    pub id: String,
    /// Maximum number of pages to return (default 100, max 1000).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i32>,
    /// Offset into the results array (default 0).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub offset: Option<i32>,
    /// Result filtering rules (max 8).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub filters: Option<Vec<Value>>,
}

impl OnPageApiNonIndexablePost {
    /// Creates a non-indexable request for the given task `id`.
    pub fn new(id: String) -> Self {
        OnPageApiNonIndexablePost {
            id,
            ..OnPageApiNonIndexablePost::default()
        }
    }
}

/// Request for [`OnPageApi::waterfall`].
/// See <https://docs.dataforseo.com/v3/on_page/waterfall/>.
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
pub struct OnPageApiWaterfallPost {
    /// Task identifier returned by the Task POST endpoint.
    pub id: String,
    /// Page URL to build the resource loading waterfall for.
    pub url: String,
    /// User-defined task identifier (max 255 characters).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tag: Option<String>,
}

impl OnPageApiWaterfallPost {
    /// Creates a waterfall request for task `id` and page `url`.
    pub fn new(id: String, url: String) -> OnPageApiWaterfallPost {
        OnPageApiWaterfallPost { id, url, tag: None }
    }
}

/// Request for [`OnPageApi::keyword_density`].
/// See <https://docs.dataforseo.com/v3/on_page/keyword_density/>.
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
pub struct OnPageApiKeywordDensityPost {
    /// Task identifier returned by the Task POST endpoint.
    pub id: String,
    /// Number of words per keyword (1-5).
    pub keyword_length: i32,
    /// Restrict results to this page URL; omit for whole-site results.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub url: Option<String>,
    /// Maximum number of keywords to return (default 100, max 1000).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i32>,
    /// Offset into the results array (default 0).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub offset: Option<i32>,
    /// Result filtering rules (max 8).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub filters: Option<Vec<Vec<String>>>,
    /// Sorting rules, each as "field,asc" or "field,desc" (max 3).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub order_by: Option<Vec<String>>,
    /// User-defined task identifier (max 255 characters).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tag: Option<String>,
}

impl OnPageApiKeywordDensityPost {
    /// Creates a keyword-density request for task `id` and the given `keyword_length`.
    pub fn new(id: String, keyword_length: i32) -> OnPageApiKeywordDensityPost {
        OnPageApiKeywordDensityPost {
            id,
            keyword_length,
            ..OnPageApiKeywordDensityPost::default()
        }
    }
}

/// Request for [`OnPageApi::microdata`].
/// See <https://docs.dataforseo.com/v3/on_page/microdata/>.
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
pub struct OnPageApiMicrodataPost {
    /// Task identifier returned by the Task POST endpoint.
    pub id: String,
    /// Page URL to validate structured markup for.
    pub url: String,
    /// User-defined task identifier (max 255 characters).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tag: Option<String>,
}

impl OnPageApiMicrodataPost {
    /// Creates a microdata request for task `id` and page `url`.
    pub fn new(id: String, url: String) -> OnPageApiMicrodataPost {
        OnPageApiMicrodataPost { id, url, tag: None }
    }
}

/// Request for [`OnPageApi::raw_html`].
/// See <https://docs.dataforseo.com/v3/on_page/raw_html/>.
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
pub struct OnPageApiRawHtmlPost {
    /// Task identifier returned by the Task POST endpoint.
    pub id: String,
    /// Page URL whose stored raw HTML to return.
    pub url: String,
}

impl OnPageApiRawHtmlPost {
    /// Creates a raw-HTML request for task `id` and page `url`.
    pub fn new(id: String, url: String) -> Self {
        OnPageApiRawHtmlPost { id, url }
    }
}

/// Request for [`OnPageApi::page_screenshot`].
/// See <https://docs.dataforseo.com/v3/on_page/page_screenshot/>.
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
pub struct OnPageApiPageScreenshotPost {
    /// Page URL to capture.
    pub url: String,
    /// Value of the Accept-Language header sent while loading the page.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub accept_language: Option<String>,
    /// Custom User-Agent header sent while loading the page.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub custom_user_agent: Option<String>,
    /// Device preset for rendering: "desktop", "mobile", or "tablet".
    #[serde(skip_serializing_if = "Option::is_none")]
    pub browser_preset: Option<String>,
    /// Viewport width used for rendering, in pixels.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub browser_screen_width: Option<i32>,
    /// Viewport height used for rendering, in pixels.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub browser_screen_height: Option<i32>,
    /// Device pixel ratio used for rendering.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub browser_screen_scale_factor: Option<f64>,
    /// Capture the entire scrollable page rather than just the viewport.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub full_page_screenshot: Option<bool>,
    /// Hide cookie-consent popups before capturing.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub disable_cookie_popup: Option<bool>,
    /// Retry using a different proxy pool if the first attempt fails.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub switch_pool: Option<bool>,
    /// Proxy location to load the page from: "us" or "de".
    #[serde(skip_serializing_if = "Option::is_none")]
    pub ip_pool_for_scan: Option<String>,
}

impl OnPageApiPageScreenshotPost {
    /// Creates a screenshot request for the given page `url`.
    pub fn new(url: String) -> Self {
        OnPageApiPageScreenshotPost {
            url,
            ..OnPageApiPageScreenshotPost::default()
        }
    }
}

/// Request for [`OnPageApi::content_parsing`].
/// See <https://docs.dataforseo.com/v3/on_page/content_parsing/>.
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
pub struct OnPageApiContentParsingPost {
    /// Task identifier returned by the Task POST endpoint.
    pub id: String,
    /// Page URL whose parsed content to return.
    pub url: String,
    /// Return the page content rendered as Markdown.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub markdown_view: Option<bool>,
}

impl OnPageApiContentParsingPost {
    /// Creates a content-parsing request for task `id` and page `url`.
    pub fn new(id: String, url: String) -> Self {
        OnPageApiContentParsingPost {
            id,
            url,
            ..OnPageApiContentParsingPost::default()
        }
    }
}

/// Request for [`OnPageApi::content_parsing_live`].
/// See <https://docs.dataforseo.com/v3/on_page/content_parsing/live/>.
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
pub struct OnPageApiContentParsingLivePost {
    /// Page URL to fetch and parse.
    pub url: String,
    /// Custom User-Agent header sent while loading the page.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub custom_user_agent: Option<String>,
    /// Device preset for rendering: "desktop", "mobile", or "tablet".
    #[serde(skip_serializing_if = "Option::is_none")]
    pub browser_preset: Option<String>,
    /// Viewport width used for rendering, in pixels.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub browser_screen_width: Option<i32>,
    /// Viewport height used for rendering, in pixels.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub browser_screen_height: Option<i32>,
    /// Device pixel ratio used for rendering.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub browser_screen_scale_factor: Option<f64>,
    /// Store the raw HTML for later retrieval.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub store_raw_html: Option<bool>,
    /// Hide cookie-consent popups before loading the page.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub disable_cookie_popup: Option<bool>,
    /// Value of the Accept-Language header sent while loading the page.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub accept_language: Option<String>,
    /// Execute page JavaScript (incurs extra cost).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub enable_javascript: Option<bool>,
    /// Emulate full browser rendering.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub enable_browser_rendering: Option<bool>,
    /// Allow XMLHttpRequest calls while rendering the page.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub enable_xhr: Option<bool>,
    /// Retry using a different proxy pool if the first attempt fails.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub switch_pool: Option<bool>,
    /// Proxy location to load the page from: "us" or "de".
    #[serde(skip_serializing_if = "Option::is_none")]
    pub ip_pool_for_scan: Option<String>,
    /// Return the page content rendered as Markdown.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub markdown_view: Option<bool>,
}

impl OnPageApiContentParsingLivePost {
    /// Creates a live content-parsing request for the given page `url`.
    pub fn new(url: String) -> Self {
        OnPageApiContentParsingLivePost {
            url,
            ..OnPageApiContentParsingLivePost::default()
        }
    }
}

/// Request for [`OnPageApi::instant_pages`].
/// See <https://docs.dataforseo.com/v3/on_page/instant_pages/>.
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
pub struct OnPageApiInstantPagesPost {
    /// Page URL to crawl.
    pub url: String,
    /// Custom User-Agent header sent while loading the page.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub custom_user_agent: Option<String>,
    /// Device preset for rendering: "desktop", "mobile", or "tablet".
    #[serde(skip_serializing_if = "Option::is_none")]
    pub browser_preset: Option<String>,
    /// Viewport width used for rendering, in pixels.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub browser_screen_width: Option<i32>,
    /// Viewport height used for rendering, in pixels.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub browser_screen_height: Option<i32>,
    /// Device pixel ratio used for rendering.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub browser_screen_scale_factor: Option<f64>,
    /// Store the raw HTML for later retrieval.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub store_raw_html: Option<bool>,
    /// Value of the Accept-Language header sent while loading the page.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub accept_language: Option<String>,
    /// Load page resources (images, scripts, stylesheets) while crawling.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub load_resources: Option<bool>,
    /// Execute page JavaScript (incurs extra cost).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub enable_javascript: Option<bool>,
    /// Emulate full browser rendering to measure Core Web Vitals.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub enable_browser_rendering: Option<bool>,
    /// Hide cookie-consent popups before loading the page.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub disable_cookie_popup: Option<bool>,
    /// Return partial results even if the request times out.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub return_despite_timeout: Option<bool>,
    /// Allow XMLHttpRequest calls while rendering the page.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub enable_xhr: Option<bool>,
    /// Custom JavaScript to execute on the page.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub custom_js: Option<String>,
    /// Validate structured microdata markup.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub validate_micromarkup: Option<bool>,
    /// Check spelling on the page using the Hunspell library.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub check_spell: Option<bool>,
    /// Custom threshold values for the checks in the response.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub checks_threshold: Option<Value>,
    /// Retry using a different proxy pool if the first attempt fails.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub switch_pool: Option<bool>,
    /// Proxy location to load the page from: "us" or "de".
    #[serde(skip_serializing_if = "Option::is_none")]
    pub ip_pool_for_scan: Option<String>,
}

impl OnPageApiInstantPagesPost {
    /// Creates an instant-pages request for the given page `url`.
    pub fn new(url: String) -> Self {
        OnPageApiInstantPagesPost {
            url,
            ..OnPageApiInstantPagesPost::default()
        }
    }
}

/// Request for [`OnPageApi::id_list`].
/// See <https://docs.dataforseo.com/v3/on_page/id_list/>.
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
pub struct OnPageApiIdListPost {
    /// Start of the time range, as "yyyy-mm-dd hh-mm-ss +00:00".
    pub datetime_from: String,
    /// End of the time range, as "yyyy-mm-dd hh-mm-ss +00:00".
    pub datetime_to: String,
    /// Maximum number of task IDs to return (default 100, max 1000).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i32>,
    /// Offset into the results array (default 0).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub offset: Option<i32>,
    /// Sort order by post date: "asc" or "desc".
    #[serde(skip_serializing_if = "Option::is_none")]
    pub sort: Option<String>,
    /// Include each task's metadata in the response.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub include_metadata: Option<bool>,
}

impl OnPageApiIdListPost {
    /// Creates an id-list request for tasks created between `datetime_from` and `datetime_to`.
    pub fn new(datetime_from: String, datetime_to: String) -> Self {
        OnPageApiIdListPost {
            datetime_from,
            datetime_to,
            ..OnPageApiIdListPost::default()
        }
    }
}

/// Request for [`OnPageApi::errors`].
/// See <https://docs.dataforseo.com/v3/on_page/errors/>.
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
pub struct OnPageApiErrorsPost {
    /// Maximum number of error records to return (default 1000, max 1000).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i32>,
    /// Offset into the results array (default 0).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub offset: Option<i32>,
    /// Restrict results to a specific API function name.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub filtered_function: Option<String>,
    /// Start of the time range (within the last 7 days).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub datetime_from: Option<String>,
    /// End of the time range (within the last 7 days).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub datetime_to: Option<String>,
}

/// Request for [`OnPageApi::force_stop`].
/// See <https://docs.dataforseo.com/v3/on_page/force_stop/>.
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
pub struct OnPageApiForceStopPost {
    /// Identifier of the crawling task to stop.
    pub id: String,
}

impl OnPageApiForceStopPost {
    /// Creates a force-stop request for the given task `id`.
    pub fn new(id: String) -> Self {
        OnPageApiForceStopPost { id }
    }
}

/// Request for [`OnPageApi::lighthouse_task_post`].
/// See <https://docs.dataforseo.com/v3/on_page/lighthouse/task_post/>.
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
pub struct OnPageApiLighthouseTaskPost {
    /// Page URL to audit with Lighthouse.
    pub url: String,
    /// Run the audit emulating a mobile device.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub for_mobile: Option<bool>,
    /// Lighthouse categories to run (e.g. "performance", "seo").
    #[serde(skip_serializing_if = "Option::is_none")]
    pub categories: Option<Vec<String>>,
    /// Specific Lighthouse audits to run.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub audits: Option<Vec<String>>,
    /// Lighthouse version to use.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub version: Option<String>,
    /// Full language name for the report (e.g. "English").
    #[serde(skip_serializing_if = "Option::is_none")]
    pub language_name: Option<String>,
    /// Language code for the report (e.g. "en").
    #[serde(skip_serializing_if = "Option::is_none")]
    pub language_code: Option<String>,
    /// User-defined task identifier (max 255 characters).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tag: Option<String>,
    /// URL notified by GET when the task completes.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub pingback_url: Option<String>,
    /// URL the results are POSTed to when the task completes.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub postback_url: Option<String>,
}

impl OnPageApiLighthouseTaskPost {
    /// Creates a Lighthouse task request for the given page `url`.
    pub fn new(url: String) -> Self {
        OnPageApiLighthouseTaskPost {
            url,
            ..OnPageApiLighthouseTaskPost::default()
        }
    }
}

/// Request for [`OnPageApi::lighthouse_live`].
/// See <https://docs.dataforseo.com/v3/on_page/lighthouse/live/>.
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
pub struct OnPageApiLighthouseLivePost {
    /// Page URL to audit with Lighthouse.
    pub url: String,
    /// Run the audit emulating a mobile device.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub for_mobile: Option<bool>,
    /// Lighthouse categories to run (e.g. "performance", "seo").
    #[serde(skip_serializing_if = "Option::is_none")]
    pub categories: Option<Vec<String>>,
    /// Specific Lighthouse audits to run.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub audits: Option<Vec<String>>,
    /// Lighthouse version to use.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub version: Option<String>,
    /// Full language name for the report (e.g. "English").
    #[serde(skip_serializing_if = "Option::is_none")]
    pub language_name: Option<String>,
    /// Language code for the report (e.g. "en").
    #[serde(skip_serializing_if = "Option::is_none")]
    pub language_code: Option<String>,
    /// Custom User-Agent header sent while loading the page.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub custom_user_agent: Option<String>,
    /// Viewport width used for rendering, in pixels.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub browser_screen_width: Option<i32>,
    /// Viewport height used for rendering, in pixels.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub browser_screen_height: Option<i32>,
    /// Device pixel ratio used for rendering.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub browser_screen_scale_factor: Option<f64>,
    /// Network throttling method: "provided", "devtools", or "simulate".
    #[serde(skip_serializing_if = "Option::is_none")]
    pub browser_network_throttling_method: Option<String>,
    /// CPU slowdown multiplier applied during the audit.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub browser_cpu_throttling_multiplier: Option<f64>,
    /// Network throttling preset applied during the audit.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub browser_network_throttling: Option<String>,
    /// User-defined task identifier (max 255 characters).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tag: Option<String>,
}

impl OnPageApiLighthouseLivePost {
    /// Creates a live Lighthouse request for the given page `url`.
    pub fn new(url: String) -> Self {
        OnPageApiLighthouseLivePost {
            url,
            ..OnPageApiLighthouseLivePost::default()
        }
    }
}