{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://dina.ai/protocol/schemas/approval-request.json",
  "title": "Dina Approval Request",
  "description": "Protocol-level approval request for risky or sensitive actions.",
  "type": "object",
  "required": [
    "schema_version",
    "approval_id",
    "operation",
    "summary",
    "status",
    "requested_by",
    "created_at"
  ],
  "properties": {
    "schema_version": {
      "const": "1"
    },
    "approval_id": {
      "type": "string",
      "minLength": 1
    },
    "session_id": {
      "type": "string"
    },
    "operation": {
      "type": "string",
      "minLength": 1
    },
    "summary": {
      "type": "string",
      "minLength": 1
    },
    "reason": {
      "type": "string"
    },
    "status": {
      "type": "string",
      "enum": ["pending", "approved", "denied", "expired", "cancelled"]
    },
    "intent_classification": {
      "type": "string",
      "enum": ["safe", "review", "flag", "block"]
    },
    "sensitivity": {
      "type": "string"
    },
    "requested_scopes": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1
      },
      "uniqueItems": true
    },
    "counterparties": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1
      },
      "uniqueItems": true
    },
    "requested_by": {
      "type": "object",
      "properties": {
        "principal": {
          "$ref": "#/$defs/did"
        },
        "actor": {
          "$ref": "#/$defs/did"
        },
        "origin": {
          "type": "string"
        },
        "auth_mode": {
          "type": "string"
        }
      },
      "additionalProperties": true
    },
    "proposed_action": {
      "type": "object",
      "additionalProperties": true
    },
    "created_at": {
      "type": "string",
      "format": "date-time"
    },
    "expires_at": {
      "type": "string",
      "format": "date-time"
    },
    "decision": {
      "type": "object",
      "properties": {
        "by": {
          "$ref": "#/$defs/did"
        },
        "at": {
          "type": "string",
          "format": "date-time"
        },
        "note": {
          "type": "string"
        }
      },
      "additionalProperties": true
    },
    "annotations": {
      "$ref": "#/$defs/named_items"
    },
    "disclosures": {
      "$ref": "#/$defs/named_items"
    },
    "extensions": {
      "$ref": "#/$defs/extensions"
    }
  },
  "additionalProperties": false,
  "$defs": {
    "did": {
      "type": "string",
      "pattern": "^did:[a-z0-9]+:.+$"
    },
    "named_items": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["name"],
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1
          },
          "value": {
            "type": ["string", "number", "integer", "boolean", "object", "array", "null"]
          }
        },
        "additionalProperties": true
      }
    },
    "extensions": {
      "type": "object",
      "propertyNames": {
        "pattern": "^[A-Za-z0-9._:-]+$"
      },
      "additionalProperties": true
    }
  }
}
