{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://tiffany.systems/api/schema/delegation.schema.json",
  "title": "Delegation",
  "description": "A grant of specific authority to a specific actor, bounded in scope, environment and time. No delegation exists today; the registry is empty and every rung of the ladder is held by nobody. A delegation grants operational permission only — it can never make content scientifically qualified.",
  "x-schema-version": "1.0.0",
  "type": "object",
  "additionalProperties": false,
  "required": ["delegation_id", "principal", "actor_type", "capabilities", "scope", "effective_from", "expires_at", "issuer", "policy_version", "status"],
  "properties": {
    "delegation_id": {"type": "string", "pattern": "^del-[a-z0-9-]+$"},
    "principal": {"type": "string", "description": "The actor this is granted to. Identity, not a role name."},
    "actor_type": {"type": "string", "enum": ["HUMAN", "ORGANISATION", "SOFTWARE_AGENT", "TIFFANY"]},
    "capabilities": {"type": "array", "minItems": 1, "items": {"type": "string", "enum": ["OBSERVE", "PREPARE_DRAFT", "PROPOSE_UPDATE", "ATTACH_APPROVED_EVIDENCE", "VALIDATE", "REQUEST_PUBLICATION", "EXECUTE_REVERSIBLE", "PUBLISH_APPROVED", "SUPERSEDE_APPROVED", "WITHDRAW_APPROVED", "RELEASE_APPROVED_SOFTWARE"]}, "description": "Enumerated explicitly. There is no wildcard and no implication between rungs in either direction."},
    "scope": {
      "type": "object", "additionalProperties": false, "required": ["environments", "resource_ids", "resource_types"],
      "properties": {
        "environments": {"type": "array", "items": {"type": "string", "enum": ["SHADOW", "PREVIEW", "PRODUCTION"]}},
        "resource_ids": {"type": "array", "items": {"type": "string"}, "description": "Explicit ids. An empty array means no resource, never all resources."},
        "resource_types": {"type": "array", "items": {"type": "string"}},
        "operation_classes": {"type": ["array", "null"], "items": {"type": "string"}}
      }
    },
    "effective_from": {"type": "string"},
    "expires_at": {"type": "string", "description": "Required. A delegation without an expiry is a standing grant, and standing grants are what turn a narrow permission into an account."},
    "issuer": {"type": "string"},
    "policy_version": {"type": "string", "description": "The policy the holder is judged against. Set by the issuer; an actor never selects the rules applied to it."},
    "prerequisites": {"type": ["array", "null"], "items": {"type": "string"}, "description": "Qualification evidence that had to exist before this grant, e.g. a completed shadow-mode comparison."},
    "status": {"type": "string", "enum": ["PROPOSED", "ACTIVE", "SUSPENDED", "REVOKED", "EXPIRED"]},
    "revocation": {"type": ["object", "null"], "additionalProperties": false, "properties": {"revoked_at": {"type": "string"}, "authority": {"type": "string"}, "reason": {"type": "string"}}},
    "audit_root": {"type": ["string", "null"]}
  }
}
