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
use bytes::Bytes;

use crate::requests::*;
use crate::types::*;

#[derive(Debug, Clone, PartialEq, PartialOrd)]
pub struct InputFile(InputFileImpl);

#[derive(Debug, Clone, PartialEq, PartialOrd)]
pub struct InputFileRef(Text);

#[derive(Debug, Clone, PartialEq, PartialOrd)]
pub struct InputFileUpload(InputFileUploadImpl);

#[derive(Debug, Clone, PartialEq, PartialOrd)]
enum InputFileImpl {
    Ref(Text),
    Path { path: Text, file_name: Option<Text> },
    Data { file_name: Text, data: Bytes },
}

#[derive(Debug, Clone, PartialEq, PartialOrd)]
enum InputFileUploadImpl {
    Path { path: Text, file_name: Option<Text> },
    Data { file_name: Text, data: Bytes },
}

impl InputFileRef {
    pub fn new(r: impl Into<Text>) -> Self {
        InputFileRef(r.into())
    }
}

impl InputFileUpload {
    pub fn with_path(path: impl Into<Text>) -> Self {
        InputFileUpload(InputFileUploadImpl::Path {
            path: path.into(),
            file_name: None,
        })
    }

    pub fn with_data(data: impl Into<Bytes>, file_name: impl Into<Text>) -> Self {
        InputFileUpload(InputFileUploadImpl::Data {
            file_name: file_name.into(),
            data: data.into(),
        })
    }

    pub fn file_name(&self, new_file_name: impl Into<Text>) -> Self {
        let mut this = self.clone();
        match &mut this.0 {
            InputFileUploadImpl::Path { file_name, .. } => *file_name = Some(new_file_name.into()),
            InputFileUploadImpl::Data { file_name, .. } => *file_name = new_file_name.into(),
        };
        this
    }
}

impl From<FileRef> for InputFile {
    fn from(value: FileRef) -> Self {
        InputFile::from(InputFileRef::from(value))
    }
}

impl<'a> From<&'a FileRef> for InputFile {
    fn from(value: &'a FileRef) -> Self {
        InputFile::from(InputFileRef::from(value))
    }
}

impl<'a> From<&'a mut FileRef> for InputFile {
    fn from(value: &'a mut FileRef) -> Self {
        InputFile::from(InputFileRef::from(value))
    }
}

impl From<FileRef> for InputFileRef {
    fn from(value: FileRef) -> Self {
        InputFileRef::new(value.inner)
    }
}

impl<'a> From<&'a FileRef> for InputFileRef {
    fn from(value: &'a FileRef) -> Self {
        InputFileRef::new(value.inner.as_str())
    }
}

impl<'a> From<&'a mut FileRef> for InputFileRef {
    fn from(value: &'a mut FileRef) -> Self {
        InputFileRef::new(value.inner.as_str())
    }
}

impl<'a> From<&'a InputFile> for InputFile {
    fn from(value: &'a InputFile) -> Self {
        value.clone()
    }
}

impl<'a> From<&'a mut InputFile> for InputFile {
    fn from(value: &'a mut InputFile) -> Self {
        value.clone()
    }
}

impl From<InputFileRef> for InputFile {
    fn from(value: InputFileRef) -> Self {
        InputFile(InputFileImpl::Ref(value.0))
    }
}

impl<'a> From<&'a InputFileRef> for InputFile {
    fn from(value: &'a InputFileRef) -> Self {
        InputFile(InputFileImpl::Ref(value.0.clone()))
    }
}

impl<'a> From<&'a mut InputFileRef> for InputFile {
    fn from(value: &'a mut InputFileRef) -> Self {
        InputFile(InputFileImpl::Ref(value.0.clone()))
    }
}

impl From<InputFileUpload> for InputFile {
    fn from(value: InputFileUpload) -> Self {
        InputFile(match value.0 {
            InputFileUploadImpl::Path { path, file_name } => {
                InputFileImpl::Path { path, file_name }
            }
            InputFileUploadImpl::Data { data, file_name } => {
                InputFileImpl::Data { data, file_name }
            }
        })
    }
}

impl<'a> From<&'a InputFileUpload> for InputFile {
    fn from(value: &'a InputFileUpload) -> Self {
        InputFile(match &value.0 {
            InputFileUploadImpl::Path { path, file_name } => InputFileImpl::Path {
                path: path.clone(),
                file_name: file_name.clone(),
            },
            InputFileUploadImpl::Data { data, file_name } => InputFileImpl::Data {
                data: data.clone(),
                file_name: file_name.clone(),
            },
        })
    }
}

impl<'a> From<&'a mut InputFileUpload> for InputFile {
    fn from(value: &'a mut InputFileUpload) -> Self {
        InputFile(match &value.0 {
            InputFileUploadImpl::Path { path, file_name } => InputFileImpl::Path {
                path: path.clone(),
                file_name: file_name.clone(),
            },
            InputFileUploadImpl::Data { data, file_name } => InputFileImpl::Data {
                data: data.clone(),
                file_name: file_name.clone(),
            },
        })
    }
}

impl<'a> From<&'a InputFileRef> for InputFileRef {
    fn from(value: &'a InputFileRef) -> Self {
        value.clone()
    }
}

impl<'a> From<&'a mut InputFileRef> for InputFileRef {
    fn from(value: &'a mut InputFileRef) -> Self {
        value.clone()
    }
}

impl<'a> From<&'a InputFileUpload> for InputFileUpload {
    fn from(value: &'a InputFileUpload) -> Self {
        value.clone()
    }
}

impl<'a> From<&'a mut InputFileUpload> for InputFileUpload {
    fn from(value: &'a mut InputFileUpload) -> Self {
        value.clone()
    }
}

impl ToMultipartValue for InputFile {
    fn to_multipart_value(&self) -> MultipartValue {
        match &self.0 {
            InputFileImpl::Ref(r) => MultipartValue::Text(r.clone()),
            InputFileImpl::Path { path, file_name } => MultipartValue::Path {
                path: path.clone(),
                file_name: file_name.clone(),
            },
            InputFileImpl::Data { file_name, data } => MultipartValue::Data {
                file_name: file_name.clone(),
                data: data.clone(),
            },
        }
    }
}