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

use serde::Serialize;

/// The type that represents a request of `files.remote.add`.
///
/// <https://api.slack.com/methods/files.remote.add>
#[derive(Clone, Debug, Serialize)]
#[serde(rename_all = "snake_case")]
pub struct FilesRemoteAddRequest {
    /// Creator defined GUID for the file.
    ///
    /// <https://api.slack.com/methods/files.remote.add#arg_external_id>
    pub external_id: String,

    /// URL of the remote file.
    ///
    /// <https://api.slack.com/methods/files.remote.add#arg_external_url>
    pub external_url: String,

    /// Title of the file being shared.
    ///
    /// <https://api.slack.com/methods/files.remote.add#arg_title>
    pub title: String,

    /// type of file
    ///
    /// <https://api.slack.com/methods/files.remote.add#arg_filetype>
    #[serde(skip_serializing_if = "Option::is_none")]
    pub filetype: Option<String>,

    /// A text file (txt, pdf, doc, etc.) containing textual search terms that are used to improve discovery of the remote file.
    ///
    /// <https://api.slack.com/methods/files.remote.add#arg_indexable_file_contents>
    #[serde(skip_serializing_if = "Option::is_none")]
    pub indexable_file_contents: Option<String>,

    /// Preview of the document via `multipart/form-data`.
    ///
    /// <https://api.slack.com/methods/files.remote.add#arg_preview_image>
    #[serde(skip_serializing_if = "Option::is_none")]
    pub preview_image: Option<String>,
}

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

    use anyhow::Result;

    #[test]
    fn test_ser_files_remote_add_0() -> Result<()> {
        let testdata = FilesRemoteAddRequest {
            external_id: "external_id dummy".into(),
            external_url: "external_url dummy".into(),
            title: "title dummy".into(),
            filetype: None,
            indexable_file_contents: None,
            preview_image: None,
        };

        let ser = serde_json::to_string(&testdata)?;
        let expected = r#"{"external_id":"external_id dummy","external_url":"external_url dummy","title":"title dummy"}"#;

        assert_eq!(ser, expected);

        Ok(())
    }

    #[test]
    fn test_ser_files_remote_add_1() -> Result<()> {
        let testdata = FilesRemoteAddRequest {
            external_id: "external_id dummy".into(),
            external_url: "external_url dummy".into(),
            title: "title dummy".into(),
            filetype: Some("filetype dummy".into()),
            indexable_file_contents: Some("indexable_file_contents dummy".into()),
            preview_image: Some("preview_image dummy".into()),
        };

        let ser = serde_json::to_string(&testdata)?;
        let expected = r#"{"external_id":"external_id dummy","external_url":"external_url dummy","title":"title dummy","filetype":"filetype dummy","indexable_file_contents":"indexable_file_contents dummy","preview_image":"preview_image dummy"}"#;

        assert_eq!(ser, expected);

        Ok(())
    }
}
