{
  "openapi": "3.0.3",
  "info": {
    "title": "ChessCore Public API",
    "version": "1.0.0",
    "description": "Scoped, tenant-isolated REST access to ChessCore."
  },
  "servers": [
    {
      "url": "https://app.chesscore.io/api/v1"
    }
  ],
  "components": {
    "securitySchemes": {
      "bearerApiKey": {
        "type": "http",
        "scheme": "bearer",
        "description": "A scoped ChessCore API key (ck_live_…) or PAT (ck_pat_…)."
      }
    },
    "schemas": {
      "Student": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "full_name": {
            "type": "string"
          },
          "status": {
            "type": "string"
          },
          "grade": {
            "type": "string",
            "nullable": true
          },
          "skill_band": {
            "type": "integer",
            "nullable": true
          },
          "internal_rating": {
            "type": "integer",
            "nullable": true
          },
          "join_date": {
            "type": "string",
            "format": "date",
            "nullable": true
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Event": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "type": {
            "type": "string"
          },
          "resource_type": {
            "type": "string"
          },
          "resource_id": {
            "type": "string"
          },
          "occurred_at": {
            "type": "string",
            "format": "date-time"
          },
          "data": {
            "type": "object"
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "type": {
                "type": "string"
              },
              "message": {
                "type": "string"
              },
              "request_id": {
                "type": "string"
              }
            }
          }
        }
      }
    }
  },
  "security": [
    {
      "bearerApiKey": []
    }
  ],
  "x-scopes": [
    "students:read",
    "students:write",
    "events:read",
    "webhooks:read",
    "webhooks:write",
    "mcp:read",
    "mcp:write",
    "mcp:admin"
  ],
  "paths": {
    "/students": {
      "get": {
        "summary": "List students, or find by exact email (?email=)",
        "security": [
          {
            "bearerApiKey": [
              "students:read"
            ]
          }
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 25
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Opaque pagination cursor from a prior response's page.next_cursor."
          },
          {
            "name": "email",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Exact-match search (blind-index); returns matching students, no pagination."
          }
        ],
        "responses": {
          "200": {
            "description": "A page of students",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Student"
                      }
                    },
                    "page": {
                      "type": "object",
                      "properties": {
                        "next_cursor": {
                          "type": "string",
                          "nullable": true
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Create a student (INT-9 Zapier/Make `create_student`)",
        "security": [
          {
            "bearerApiKey": [
              "students:write"
            ]
          }
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "full_name"
                ],
                "properties": {
                  "full_name": {
                    "type": "string"
                  },
                  "email": {
                    "type": "string",
                    "format": "email"
                  },
                  "grade": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The created student",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Student"
                }
              }
            }
          }
        }
      }
    },
    "/students/{id}/notes": {
      "post": {
        "summary": "Append a note to a student (INT-9 Zapier/Make `add_note`)",
        "security": [
          {
            "bearerApiKey": [
              "students:write"
            ]
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "body"
                ],
                "properties": {
                  "body": {
                    "type": "string",
                    "maxLength": 10000
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The created note"
          }
        }
      }
    },
    "/events": {
      "get": {
        "summary": "List domain events (newest-first via cursor, or poll forward via after)",
        "security": [
          {
            "bearerApiKey": [
              "events:read"
            ]
          }
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 25
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Opaque pagination cursor from a prior response's page.next_cursor."
          },
          {
            "name": "type",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter to one catalog event type; unknown types are rejected (400)."
          },
          {
            "name": "after",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Poll forward: only events strictly after this cursor, oldest-first."
          }
        ],
        "responses": {
          "200": {
            "description": "A page of events",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Event"
                      }
                    },
                    "page": {
                      "type": "object",
                      "properties": {
                        "next_cursor": {
                          "type": "string",
                          "nullable": true
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/webhook_endpoints": {
      "post": {
        "summary": "Register a webhook endpoint + event-type subscriptions (REST Hook subscribe)",
        "security": [
          {
            "bearerApiKey": [
              "webhooks:write"
            ]
          }
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "url",
                  "event_types"
                ],
                "properties": {
                  "url": {
                    "type": "string",
                    "format": "uri",
                    "description": "Public https URL (SSRF-vetted at registration)."
                  },
                  "event_types": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "minItems": 1
                  },
                  "description": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Endpoint id + the signing secret (returned ONCE)"
          }
        }
      }
    },
    "/webhook_endpoints/{id}": {
      "delete": {
        "summary": "Unsubscribe a webhook endpoint: disables it and removes its subscriptions (REST Hook unsubscribe)",
        "security": [
          {
            "bearerApiKey": [
              "webhooks:write"
            ]
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Deleted"
          },
          "404": {
            "description": "No such endpoint"
          }
        }
      }
    }
  }
}
