ocm-types 0.2.1

Types required to implement the OpenCloudMesh filesharing protocol
Documentation
// SPDX-FileCopyrightText: 2026 Matthias Kraus <info@opengeomesh.org>
//
// SPDX-License-Identifier: LGPL-3.0-or-later

use serde::{Deserialize, Serialize};
use serde_json::Value;

#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct NewNotification {
    /// A notification type that is understandable for both humans and
    /// machines (e.g. no use of special characters) providing more
    /// information on the cause of the error.
    /// Values that MAY be used by implementations are:
    /// `SHARE_ACCEPTED`, `SHARE_DECLINED`, `REQUEST_RESHARE`,
    /// `SHARE_UNSHARED`, `RESHARE_UNDO`, `RESHARE_CHANGE_PERMISSION`,
    /// `USER_REMOVED`.
    pub notification_type: String,
    /// Resource type (file, folder, user, calendar, contact, ...)
    pub resource_type: String,
    /// Identifier of the shared resource. If the resourceType is `file`,
    /// then see `NewShare/providerId` for the required information.
    /// If the resourceType is `user`, then this is the user identifier
    /// previously sent via `/invite-accepted`.
    pub provider_id: String,
    /// Optional additional parameters, depending on the notification
    /// and the resource type.
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub notification: Option<Value>,
}

#[cfg(test)]
mod tests {
    use serde_json::json;

    use super::NewNotification;

    #[test]
    fn serde_1() {
        let notification =  NewNotification {
            notification_type: "SHARE_ACCEPTED".to_string(),
            resource_type: "file".to_string(),
            provider_id: "7c084226-d9a1-11e6-bf26-cec0c932ce01".to_string(),
            notification: Some(json!({
                "message": "Recipient accepted the share",
                "sharedSecret": "hfiuhworzwnur98d3wjiwhr"
            }))
        };

        let json = json!({
            "notificationType": "SHARE_ACCEPTED",
            "resourceType": "file",
            "providerId": "7c084226-d9a1-11e6-bf26-cec0c932ce01",
            "notification": {
                "message": "Recipient accepted the share",
                "sharedSecret": "hfiuhworzwnur98d3wjiwhr"
            }
        });
        assert_eq!(serde_json::to_value(notification).unwrap() ,json);
    }
    
    #[test]
    fn serde_2() {
        let notification =  NewNotification {
            notification_type: "USER_REMOVED".to_string(),
            resource_type: "user".to_string(),
            provider_id: "51dc30ddc473d43a6011e9ebba6ca770".to_string(),
            notification: None
        };

        let json = json!({
            "notificationType": "USER_REMOVED",
            "resourceType": "user",
            "providerId": "51dc30ddc473d43a6011e9ebba6ca770",
        });
        assert_eq!(serde_json::to_value(notification).unwrap() ,json);
    }
}
//   example:
//     shareWasAccepted:
//       notificationType: SHARE_ACCEPTED
//       resourceType: file
//       providerId: 
//       notification:
//         message: Recipient accepted the share
//         sharedSecret: 
//     userWasRemoved:
//       notificationType: USER_REMOVED
//       resourceType: user
//       providerId: