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
use crate::url::GraphUrl;
use graph_core::resource::ResourceIdentity;
use handlebars::Handlebars;
use reqwest::header::{HeaderMap, HeaderValue};
use reqwest::Method;
use std::fmt::Debug;
use std::path::PathBuf;
use std::time::Duration;

#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum RequestType {
    Basic,
    Redirect,
    Multipart,
}

impl Default for RequestType {
    fn default() -> Self {
        RequestType::Basic
    }
}

pub enum RequestAttribute<Body, Form> {
    Token(String),
    Ident(ResourceIdentity),
    Url(GraphUrl),
    Method(reqwest::Method),
    Body(Body),
    BodyFile(PathBuf),
    Headers(HeaderMap),
    ClearHeaders,
    Download(PathBuf),
    Upload(PathBuf),
    Form(Form),
    RequestType(RequestType),
}

pub struct GraphRequest<Client, Body, Form> {
    pub(crate) token: String,
    pub(crate) ident: ResourceIdentity,
    pub(crate) client: Client,
    pub(crate) registry: Handlebars,
    pub url: GraphUrl,
    pub method: Method,
    pub body: Option<Body>,
    pub headers: HeaderMap<HeaderValue>,
    pub upload_session_file: Option<PathBuf>,
    pub download_dir: Option<PathBuf>,
    pub form: Option<Form>,
    pub req_type: RequestType,
    pub timeout: Duration,
}

impl<Client, Body, Form> Debug for GraphRequest<Client, Body, Form> {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("GraphRequest")
            .field("token", &"[REDACTED]")
            .field("ident", &self.ident)
            .field("url", &self.url)
            .field("method", &self.method)
            .field("headers", &self.headers)
            .field("upload_session_file", &self.upload_session_file)
            .field("download_dir", &self.download_dir)
            .field("req_type", &self.req_type)
            .finish()
    }
}

impl<Client, Body, Form> AsRef<GraphUrl> for GraphRequest<Client, Body, Form> {
    fn as_ref(&self) -> &GraphUrl {
        &self.url
    }
}

impl<Client, Body, Form> AsMut<GraphUrl> for GraphRequest<Client, Body, Form> {
    fn as_mut(&mut self) -> &mut GraphUrl {
        &mut self.url
    }
}