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
use serde::Serialize;
use serde_json::{json, Value};

use super::GQLLeetcodeQuery;

const QUERY: &str = r#"
query problemsetQuestionList($categorySlug: String, $limit: Int, $skip: Int, $filters: QuestionListFilterInput) {
    problemsetQuestionList: questionList(
        categorySlug: $categorySlug
        limit: $limit
        skip: $skip
        filters: $filters
    ) {
        total: totalNum
        questions: data {
            acRate
            difficulty
            freqBar
            frontendQuestionId: questionFrontendId
            isFavor
            paidOnly: isPaidOnly
            status
            title
            titleSlug
            topicTags {
                name
                id
                slug
            }
            hasSolution
            hasVideoSolution
        }
    }
}"#;

#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
struct Filters(Value);

#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
struct Variables {
    category_slug: String,
    limit: i32,
    skip: i32,
    filters: Filters,
}

impl Default for Variables {
    fn default() -> Self {
        Self {
            category_slug: "".to_string(),
            limit: 1,
            skip: 0,
            filters: Filters(json!({})),
        }
    }
}

impl Variables {
    pub fn new(limit: i32, skip: i32) -> Self {
        Self {
            limit,
            skip,
            ..Default::default()
        }
    }
}

#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Query {
    query: &'static str,
    variables: Variables,
}

impl Query {
    pub fn new(limit: i32, skip: i32) -> Self {
        Self {
            variables: Variables::new(limit, skip),
            ..Default::default()
        }
    }
}

impl Default for Query {
    fn default() -> Self {
        Self {
            query: QUERY,
            variables: Variables::default(),
        }
    }
}
use crate::deserializers::problemset_question_list::Root;

impl GQLLeetcodeQuery for Query {
    type T = Root;
}