{
    "$id": "https://alwaysai.co/cloud-message-schema.json",
    "title": "cloud_message",
    "$schema": "https://json-schema.org/draft/2019-09/schema",
    "description": "The messaging payload structure for messages sent from device agent to the cloud",
    "type": "object",
    "properties": {
        "timestamp": {
            "type": "string"
        },
        "deviceId": {
            "description": "Device UUID of device sending the message",
            "type": "string"
        },
        "topic": {
            "oneOf": [{ "$ref": "#/$defs/toCloud" }]
        },
        "messageType": {
            "type": "string",
            "enum": [
                "signed_urls_request"
            ]
        },
        "txId": {
            "$ref": "https://alwaysai.co/common-schema.json#/$defs/txId"
        },
        "payload": {
            "type": "object"
        }
    },
    "allOf": [
        {
            "if": {
                "properties": {
                    "messageType": { "const": "signed_urls_request" }
                }
            },
            "then": {
                "properties": {
                    "payload": { "$ref": "https://alwaysai.co/signed-urls-request-schema.json" }
                }
            }
        }
    ],
    "required": ["timestamp", "deviceId", "txId", "payload", "messageType"],
    "$defs": {
        "toCloud": {
            "description": "Messages sent from the device agent to cloud backend client",
            "type": "string",
            "pattern": "to-cloud/aai-device/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"
        }
    }
}
