{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://xcathletes.org/contract/schemas/grant.json",
  "title": "grant",
  "description": "POST /v1/grants, POST /v1/join-codes/redeem, DELETE /v1/grants/{id}: the team-to-person authorization link (GR-01..07). Response schema, PRIN-04 open.",
  "type": "object",
  "additionalProperties": true,
  "required": [
    "id",
    "person_id",
    "state",
    "training_access",
    "checkins_access"
  ],
  "properties": {
    "id": {
      "type": "string",
      "pattern": "^[0-9a-f]{32}$"
    },
    "person_id": {
      "type": "string",
      "description": "A pre-existing platform id (a legacy person predating the /v1/ contract) or a new PRIN-05 128-bit hex id may both appear here; format is not otherwise constrained."
    },
    "state": {
      "type": "string",
      "enum": [
        "provisional",
        "pending",
        "accepted",
        "revoked"
      ],
      "description": "GR-01..03. An unrecognized value falls back to `revoked` (treat the grant as ended; the more restrictive assumption)."
    },
    "training_access": {
      "type": "string",
      "enum": [
        "none",
        "read",
        "write"
      ],
      "description": "GR-07. An unrecognized value falls back to `none`."
    },
    "checkins_access": {
      "type": "string",
      "enum": [
        "none",
        "read",
        "write"
      ],
      "description": "GR-07: separately grantable from training_access (ENT-07). An unrecognized value falls back to `none`."
    },
    "log_visible_from": {
      "type": [
        "string",
        "null"
      ],
      "format": "date",
      "description": "GR-04's visibility-window clamp, when a future read serves it."
    },
    "history_ack_at": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "revoked_at": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    }
  },
  "$defs": {
    "inviteRequest": {
      "title": "grant invite request",
      "description": "POST /v1/grants (GR-01, Tier 3). Request schema, PRIN-04 strict.",
      "type": "object",
      "additionalProperties": false,
      "required": [
        "person_id"
      ],
      "properties": {
        "person_id": {
          "type": "string",
          "description": "A pre-existing platform id (a legacy person predating the /v1/ contract) or a new PRIN-05 128-bit hex id may both appear here; format is not otherwise constrained."
        }
      }
    },
    "redeemRequest": {
      "title": "join code redeem request",
      "description": "POST /v1/join-codes/redeem (ID-02, Tier 3): the code travels in the JSON body, never the URL. Request schema, PRIN-04 strict.",
      "type": "object",
      "additionalProperties": false,
      "required": [
        "code"
      ],
      "properties": {
        "code": {
          "type": "string",
          "minLength": 1
        }
      }
    }
  }
}
