{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://rctp.dev/schemas/grant-introspection.schema.json",
  "title": "Agent Grant introspection response",
  "description": "RFC 7662 introspection response for an Agent Grant access token (binding 3.3; Draft 0.4 5.1, A.1). The gateway introspects on every seller-side call and never caches the answer (INV-7). An inactive token answers active false and, for tokens the authorization server issued, grant_status (B-3).",
  "type": "object",
  "properties": {
    "active": {
      "type": "boolean"
    },
    "scope": {
      "type": "string",
      "pattern": "^dev\\.rctp\\.(listing|deal):[a-z][a-z0-9_]*( dev\\.rctp\\.(listing|deal):[a-z][a-z0-9_]*)*$",
      "description": "Granted RCTP scopes, space-separated"
    },
    "sub": {
      "$ref": "common.schema.json#/$defs/Pseudonym"
    },
    "client_id": {
      "type": "string",
      "minLength": 1,
      "maxLength": 256
    },
    "iat": {
      "type": "integer"
    },
    "exp": {
      "type": "integer",
      "description": "Access token expiry"
    },
    "token_type": {
      "const": "Bearer"
    },
    "cnf": {
      "type": "object",
      "properties": {
        "jkt": {
          "$ref": "common.schema.json#/$defs/Thumbprint"
        }
      },
      "additionalProperties": false,
      "required": [
        "jkt"
      ]
    },
    "grant_status": {
      "type": "string",
      "enum": [
        "active",
        "revoked",
        "expired"
      ],
      "description": "B-3: lets the gateway answer grant_revoked or grant_expired"
    },
    "authorization_details": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/AgentGrantAuthorizationDetail"
      },
      "minItems": 1,
      "maxItems": 1
    }
  },
  "additionalProperties": false,
  "required": [
    "active"
  ],
  "allOf": [
    {
      "if": {
        "properties": {
          "active": {
            "const": true
          }
        },
        "required": [
          "active"
        ]
      },
      "then": {
        "required": [
          "scope",
          "sub",
          "client_id",
          "iat",
          "exp",
          "token_type",
          "cnf",
          "grant_status",
          "authorization_details"
        ]
      },
      "else": {
        "propertyNames": {
          "enum": [
            "active",
            "grant_status"
          ]
        }
      }
    }
  ],
  "$defs": {
    "AgentGrantAuthorizationDetail": {
      "type": "object",
      "properties": {
        "type": {
          "const": "dev.rctp.agent_grant"
        },
        "grant_id": {
          "$ref": "common.schema.json#/$defs/GrantId"
        },
        "operator": {
          "$ref": "common.schema.json#/$defs/ProfileUrl"
        },
        "agent_id": {
          "$ref": "common.schema.json#/$defs/AgentId"
        },
        "jkt": {
          "$ref": "common.schema.json#/$defs/Thumbprint"
        },
        "tiers": {
          "type": "object",
          "description": "Tier per granted scope, within each scope's allowed_tiers",
          "propertyNames": {
            "$ref": "common.schema.json#/$defs/Scope"
          },
          "additionalProperties": {
            "$ref": "common.schema.json#/$defs/GrantTier"
          },
          "minProperties": 1
        },
        "exp": {
          "type": "integer",
          "description": "Grant expiry: at most 90 days after issue"
        }
      },
      "additionalProperties": false,
      "required": [
        "type",
        "grant_id",
        "operator",
        "agent_id",
        "jkt",
        "tiers",
        "exp"
      ],
      "description": "RFC 9396 authorization details of type dev.rctp.agent_grant. Carries no prices."
    }
  }
}
