{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "APIInvocation",
    "type": "object",
    "description": "Schema for logging API invocation events, including parameters, processing details, and status.",
    "additionalProperties": false,
    "properties": {
        "log_context": {
            "$ref": "/resources/schema/analytics/client/v4/LogContext.json",
            "description": "Required Log Context Reference"
        },
        "event_name": {
            "type": "string",
            "enum": ["API_INVOCATION"],
            "description": "Event type name: API_INVOCATION"
        },
        "schema_definition": {
            "type": "string",
            "enum": ["APIInvocationEvent"],
            "description": "Schema definition name"
        },
        "api_name": {
            "type": "string",
            "description": "The name of the API being invoked"
        },
        "parameters": {
            "type": "array",
            "description": "List of API parameters, each with name and value as stringified JSON.",
            "items": {
                "type": "object",
                "properties": {
                    "key": {
                        "type": "string",
                        "description": "The parameter name"
                    },
                    "value": {
                        "type": "string",
                        "description": "The parameter value as JSON string (escaped for JSON storage)"
                    }
                },
                "required": ["key", "value"],
                "additionalProperties": false
            }
        },
        "invocation_utc_timestamp": {
            "type": "integer",
            "description": "UTC timestamp in milliseconds of the API invocation"
        },
        "invocation_caller": {
            "type": "string",
            "description": "The caller of the API invocation"
        },
        "invocation_callee": {
            "type": "string",
            "description": "The callee of the API invocation"
        },
        "request_id": {
            "type": "string",
            "description": "The uuid for this request invocation, trace the api invocation: APP -> SDK -> Cloud"
        },   
        "response_time": {
            "type": "number",
            "description": "Processing time for the API invocation, in milliseconds"
        },
        "response_status": {
            "type": "string",
            "enum": ["SUCCESS", "FAILURE"],
            "description": "Status of the API invocation"
        },
        "error_code": {
            "type": "string",
            "description": "Optional error code if the API invocation failed"
        },
        "message": {
            "type": "string",
            "description": "Optional message for either success or failure"
        }
    },
    "required": [
        "log_context",
        "event_name",
        "schema_definition",
        "api_name",
        "invocation_utc_timestamp",
        "response_time",
        "response_status"
    ]
}