{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://asic-format.org/asic-1.0.schema.json",
  "title": "ASIC event 1.0",
  "description": "A behavioral event described by four dimensions: action, scope, item, context.",
  "type": "object",
  "required": ["timestamp", "action", "scope", "items"],
  "additionalProperties": false,
  "properties": {
    "asic_version": { "type": "string", "const": "1.0" },
    "timestamp": { "type": "string", "format": "date-time" },
    "action": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9_]*$",
      "description": "Normalized past-tense verb, for example completed, viewed, started, cancelled."
    },
    "scope": {
      "type": "object",
      "required": ["grain", "id"],
      "properties": {
        "grain": { "type": "string", "pattern": "^[a-z][a-z0-9_]*$" },
        "id": { "type": "string", "minLength": 1 },
        "parent_grain": { "type": "string", "pattern": "^[a-z][a-z0-9_]*$" },
        "parent_id": { "type": "string", "minLength": 1 }
      },
      "additionalProperties": false
    },
    "items": {
      "type": "array",
      "minItems": 1,
      "description": "The objects of the action. At least one item is required.",
      "items": {
        "type": "object",
        "required": ["type", "id"],
        "properties": {
          "type": { "type": "string", "pattern": "^[a-z][a-z0-9_]*$" },
          "id": { "type": "string", "minLength": 1 },
          "category": { "type": "string" },
          "value": { "type": "number" },
          "currency": { "type": "string", "pattern": "^[A-Z]{3}$" },
          "quantity": { "type": "number" }
        },
        "additionalProperties": true
      }
    },
    "context": {
      "type": "object",
      "description": "Circumstances of the action. Never the object of the action.",
      "additionalProperties": {
        "type": ["string", "number", "boolean", "null"]
      }
    },
    "source": { "type": "string" },
    "raw_ref": { "type": "string", "description": "Pointer to the stored raw payload." }
  }
}
