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

use crate::utils::Snowflake;

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Attachment {
    pub id: Snowflake,
    pub filename: String,
    pub description: Option<String>,
    pub content_type: Option<String>,
    pub size: u64,
    pub url: String,
    pub proxy_url: String,
    pub height: Option<u64>,
    pub width: Option<u64>,
    pub message_id: Snowflake,
    pub ephemeral: Option<bool>,
    pub duration_secs: Option<f32>,
    pub waveform: Option<String>,
    #[serde(skip_serializing)]
    pub content: Vec<u8>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]

pub struct PartialDiscordFileAttachment {
    pub id: Option<Snowflake>,
    pub filename: String,
    pub description: Option<String>,
    pub content_type: Option<String>,
    pub size: Option<i64>,
    pub url: Option<String>,
    pub proxy_url: Option<String>,
    pub height: Option<i32>,
    pub width: Option<i32>,
    pub ephemeral: Option<bool>,
    pub duration_secs: Option<f32>,
    pub waveform: Option<String>,
    #[serde(skip_serializing)]
    pub content: Vec<u8>,
}

impl PartialDiscordFileAttachment {
    /**
    Moves `self.content` out of `self` and returns it.
    # Returns
    Vec<u8>
     */
    pub fn move_content(self) -> (Vec<u8>, PartialDiscordFileAttachment) {
        let content = self.content;
        let updated_struct = PartialDiscordFileAttachment {
            id: self.id,
            filename: self.filename,
            description: self.description,
            content_type: self.content_type,
            size: self.size,
            url: self.url,
            proxy_url: self.proxy_url,
            height: self.height,
            width: self.width,
            ephemeral: self.ephemeral,
            duration_secs: self.duration_secs,
            waveform: self.waveform,
            content: Vec::new(),
        };
        (content, updated_struct)
    }

    pub fn move_filename(self) -> (String, PartialDiscordFileAttachment) {
        let filename = self.filename;
        let updated_struct = PartialDiscordFileAttachment {
            id: self.id,
            filename: String::new(),
            description: self.description,
            content_type: self.content_type,
            size: self.size,
            url: self.url,
            proxy_url: self.proxy_url,
            height: self.height,
            width: self.width,

            ephemeral: self.ephemeral,
            duration_secs: self.duration_secs,
            waveform: self.waveform,
            content: self.content,
        };
        (filename, updated_struct)
    }

    pub fn move_content_type(self) -> (Option<String>, PartialDiscordFileAttachment) {
        let content_type = self.content_type;
        let updated_struct = PartialDiscordFileAttachment {
            id: self.id,
            filename: self.filename,
            description: self.description,
            content_type: None,
            size: self.size,
            url: self.url,
            proxy_url: self.proxy_url,
            height: self.height,
            width: self.width,
            ephemeral: self.ephemeral,
            duration_secs: self.duration_secs,
            waveform: self.waveform,
            content: self.content,
        };
        (content_type, updated_struct)
    }

    pub fn set_id(&mut self, id: Snowflake) {
        self.id = Some(id);
    }
}