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

use serde::Serialize;

/// The type that represents a request of `files.info`.
///
/// <https://api.slack.com/methods/files.info>
#[derive(Clone, Debug, Serialize)]
pub struct FilesInfoRequest {
    /// Specify a file by providing its ID.
    ///
    /// <https://api.slack.com/methods/files.info#arg_file>
    pub file: String,

    /// Number of items to return per page.
    ///
    /// <https://api.slack.com/methods/files.info#arg_count>
    #[serde(skip_serializing_if = "Option::is_none")]
    pub count: Option<i64>,

    /// Parameter for pagination.
    ///
    /// <https://api.slack.com/methods/files.info#arg_cursor>
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cursor: Option<String>,

    /// The maximum number of items to return.
    ///
    /// <https://api.slack.com/methods/files.info#arg_limit>
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i64>,

    /// Page number of results to return.
    ///
    /// <https://api.slack.com/methods/files.info#arg_page>
    #[serde(skip_serializing_if = "Option::is_none")]
    pub page: Option<i64>,
}

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

    #[test]
    fn test_ser_files_info_request() -> anyhow::Result<()> {
        let testdata = FilesInfoRequest {
            file: "F2147483862".to_string(),
            count: Some(20),
            cursor: Some("dXNlcjpVMDYxTkZUVDI=".to_string()),
            limit: Some(20),
            page: Some(2),
        };
        let serialized = serde_json::to_string(&testdata)?;

        let deserialized: serde_json::Value = serde_json::from_str(&serialized)?;
        assert_eq!(deserialized["file"], testdata.file);
        assert_eq!(deserialized["count"], testdata.count.unwrap());
        assert_eq!(deserialized["cursor"], testdata.cursor.unwrap());
        assert_eq!(deserialized["limit"], testdata.limit.unwrap());
        assert_eq!(deserialized["page"], testdata.page.unwrap());

        Ok(())
    }
}
