//! The type that represents a request of `files.getUploadURLExternal`.
//!
//! <https://api.slack.com/methods/files.getUploadURLExternal>

use serde::Serialize;

/// The type that represents a request of `files.getUploadURLExternal`.
///
/// <https://api.slack.com/methods/files.getUploadURLExternal>
#[derive(Clone, Debug, Serialize)]
pub struct FilesGetUploadUrlExternalRequest {
    /// Name of the file being uploaded.
    ///
    /// <https://api.slack.com/methods/files.getUploadURLExternal#arg_filename>
    pub filename: String,

    /// Size in bytes of the file being uploaded.
    ///
    /// <https://api.slack.com/methods/files.getUploadURLExternal#arg_length>
    pub length: usize,

    /// Description of image for screen-reader.
    ///
    /// <https://api.slack.com/methods/files.getUploadURLExternal#arg_alt_txt>
    #[serde(skip_serializing_if = "Option::is_none")]
    pub alt_txt: Option<String>,

    /// Syntax type of the snippet being uploaded.
    ///
    /// <https://api.slack.com/methods/files.getUploadURLExternal#arg_snippet_type>
    #[serde(skip_serializing_if = "Option::is_none")]
    pub snippet_type: Option<String>,
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_ser_files_get_upload_url_external_request() -> anyhow::Result<()> {
        let testdata = FilesGetUploadUrlExternalRequest {
            filename: "laughingoutloudcat.jpg".to_string(),
            length: 53072,
            alt_txt: Some(
                "Aerial view of the Bixby Bridge and coastline of the Big Sur area in California"
                    .to_string(),
            ),
            snippet_type: Some("python".to_string()),
        };
        let serialized = serde_json::to_string(&testdata)?;

        let deserialized: serde_json::Value = serde_json::from_str(&serialized)?;
        assert_eq!(deserialized["filename"], testdata.filename);
        assert_eq!(deserialized["length"], testdata.length);
        assert_eq!(deserialized["alt_txt"], testdata.alt_txt.unwrap());
        assert_eq!(deserialized["snippet_type"], testdata.snippet_type.unwrap());

        Ok(())
    }
}
