//! The Share plugin allows sharing files, text content and URLs.
use serde::{Deserialize, Serialize};

#[cfg(not(feature = "std"))]
use alloc::string::String;

/// This packet is an upload request.
///
/// <https://invent.kde.org/network/kdeconnect-meta/blob/master/protocol.md#kdeconnectsharerequest>
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct ShareRequestPacket {
    /// Name of the file being transferred. If the packet contains this field, it will be accompanied by payload transfer information.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    pub filename: Option<String>,

    /// Creation time of the file being transferred as a UNIX epoch timestamp (ms).
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    pub creation_time: Option<u64>,

    /// Modification time of the file being transferred as a UNIX epoch timestamp (ms).
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    pub last_modified: Option<u64>,

    /// Whether a received file should be opened when the transfer completes.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    pub open: Option<bool>,

    /// Number of files in a composite file transfer.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    pub number_of_files: Option<u64>,

    /// Total size in bytes of a composite file transfer.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    pub total_payload_size: Option<u64>,

    /// Text content being shared. The receiving device decides how to present to text to the user.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    pub text: Option<String>,

    /// URL being shared. The receiving device will typically open the URL with the default handler for the URI scheme.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    pub url: Option<String>,
}

/// This packet is the metadata for a multi-file transfer. By convention it is sent in advance of
/// the packets containing the payload, which will include the same fields, potentially with updated totals.
///
/// <https://invent.kde.org/network/kdeconnect-meta/blob/master/protocol.md#kdeconnectsharerequestupdate>
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct ShareRequestUpdatePacket {
    /// Number of files in a multi-file transfer.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    pub number_of_files: Option<u64>,

    /// Total size in bytes of a multi-file transfer.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    pub total_payload_size: Option<u64>,
}
