{
 "openapi": "3.1.0",
 "info": {
  "title": "saMas Quran Partner API",
  "version": "1.0.0",
  "description": "The saMas Quran Partner API is the open contract between a madrasa running saMas School and a Quran reading app its families use. Any app may implement it; the first app to do so is the reference implementation, and nothing here depends on it.\n\nA school admin connects an app under Settings and receives a per-school partner key (`sk_partner_` plus 48 hex characters, sent as `X-Api-Key`) and a webhook signing secret. The key works only on `/v1/partner/*`; a session or school key is refused here (403) and a partner key is refused everywhere else (401). The app publishes a manifest at `https://<app>/.well-known/samas-quran-partner.json` naming its webhook address and capabilities; saMas School reads it daily.\n\n**Linking.** A teacher shows the halaqa a six-character class code (never 0, O, 1 or I). The student types it in the app; the app calls `POST /partner/claims` and shows the first names it receives; the student taps their own; the app calls `POST /partner/links` with the claim and pick tokens. The link is **pending** until a parent approves it on the school's family site; the app learns the answer from the `link.approved` or `link.revoked` webhook (or by reading `GET /partner/links/{student_ref}`). From then on `student_ref` is the only id the app holds for the student: no saMas School student id, admission number, fee, phone or guardian detail ever appears in an answer or a webhook, and the school stores only a hash of the app's account id.\n\n**While linked** the app receives `lesson.assigned`, `lesson.graded` and `juz.tested`, may read the open homework, may post the student's home reading (`POST /partner/practice`, a day at a time, exact ayahs and estimated minutes), and, where the school allows recording, may upload recitations and read the teacher's feedback. A parent, the school, the student (through a parent) or the app itself may end the link; after `link.revoked` every call about that student answers `NOT_LINKED`.\n\n**Webhooks** are signed like every saMas School webhook: HMAC SHA-256 over `${timestamp}.${body}` in `X-Samas-Signature` (`v1=...`), with `X-Samas-Event`, `X-Samas-Delivery` and `X-Samas-Timestamp`; retried on the house schedule; a delivery queued before an unlink and sent after it is dropped. The envelope is `{ id, event, occurred_at, school_id, data, meta }` where `data` carries `student_ref`, `first_name`, `halaqa` and the event's own fields.\n\n**Text.** Both sides use the Hafs (Kufan) count: 114 surahs, 6,236 ayahs, 30 ajza; a word index is the 0-based position after splitting the Uthmani ayah on spaces. `GET /partner/me` states the text source the school uses. Dates are `YYYY-MM-DD`, moments RFC 3339. The house envelope applies: `{ data, meta: { request_id } }` or `{ error: { code, message, hint, docs } }`; 1,200 requests a minute per key.",
  "contact": {
   "name": "saMas School",
   "url": "https://samas.school"
  },
  "x-audience": "internal"
 },
 "servers": [
  {
   "url": "https://api.samas.school/v1",
   "description": "Production"
  },
  {
   "url": "https://api-beta.samas.school/v1",
   "description": "Beta (demo schools only)"
  }
 ],
 "security": [
  {
   "partnerKey": []
  }
 ],
 "tags": [
  {
   "name": "Partner",
   "description": "Linking, homework, home practice, recitations, feedback and live sabaq for a Quran reading app a madrasa connected."
  }
 ],
 "paths": {
  "/partner/me": {
   "get": {
    "tags": [
     "Partner"
    ],
    "summary": "Who am I",
    "description": "The partner this key belongs to, the school, the scopes, the link counts and the contract version and text source.\n\n**Who can call:** partnerKey.\n\n**Response 200:** `{ data, meta }` where `data` is one PartnerMe.\n\n| Field | Type | Notes |\n|---|---|---|\n| `partner` | object | Always present. |\n| `school` | object | Always present. |\n| `scopes` | array of string | Always present. |\n| `links` | object | Always present. |\n| `contract` | object | Always present. |\n\n**Errors**\n\n- 400 validation (UNKNOWN_FIELD, MISSING_FIELD, INVALID_TYPE, TEXT_TOO_LONG, INVALID_ENUM, OUT_OF_RANGE and others; see Validation rules)\n- 401 UNAUTHENTICATED or TOKEN_EXPIRED\n- 403 NOT_ALLOWED (role, scope, school or read-only View-as)\n- 429 RATE_LIMITED (see Retry-After)",
    "parameters": [
     {
      "$ref": "#/components/parameters/request_id"
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "$ref": "#/components/schemas/PartnerMe"
          }
         },
         "required": [
          "data"
         ]
        },
        "example": {
         "data": {
          "partner": {
           "id": "2f1c6a0e-8d7b-4c1e-9a55-3b1f0c2d4e6f",
           "name": "string",
           "slug": "string",
           "capabilities": [
            "string"
           ]
          },
          "school": {
           "name": "string"
          },
          "scopes": [
           "string"
          ],
          "links": {
           "active": 1,
           "pending": 1
          },
          "contract": {
           "version": "string",
           "docs": "https://erp.example.pk/samas/hook",
           "text": "string",
           "word_index": "string"
          }
         },
         "meta": {
          "request_id": "req_01J8Z3X4",
          "generated_at": "2026-09-22T09:30:00Z"
         }
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "429": {
      "$ref": "#/components/responses/TooManyRequests"
     }
    },
    "x-partner-only": true,
    "security": [
     {
      "partnerKey": []
     }
    ]
   }
  },
  "/partner/claims": {
   "post": {
    "tags": [
     "Partner"
    ],
    "summary": "Claim a class code",
    "description": "Step one of linking: the student typed a class code in the app. Answers the school and halaqa names and the halaqa's first names behind one-time pick tokens, valid 15 minutes. CODE_INVALID, CODE_EXPIRED, CODE_USED.\n\n**Who can call:** partnerKey. API keys need scope `partner:links`.\n\n**Request body** (JSON; unknown fields are rejected)\n\n| Field | Type | Rules |\n|---|---|---|\n| `code` | string | Required; 6 to 8 characters; Six characters; case and spaces are ignored. |\n| `external_user_id` | string | Required; 3 to 200 characters; The app's own id for the account (hashed by the school, never stored in the clear). |\n| `display_name` | string | Optional; at most 40 characters; What to show the parent, optional. |\n\n**Response 201:** `{ data, meta }` where `data` is one Claim.\n\n| Field | Type | Notes |\n|---|---|---|\n| `claim_token` | string | Always present; at most 64 characters. |\n| `expires_at` | string | Always present; timestamp with offset or Z (RFC 3339). |\n| `school` | object | Always present. |\n| `halaqa` | object | Always present. |\n| `teacher` | string | May be omitted; may be null; at most 60 characters. |\n| `students` | array of ClaimStudent | Always present. |\n\n**Errors**\n\n- 400 validation (UNKNOWN_FIELD, MISSING_FIELD, INVALID_TYPE, TEXT_TOO_LONG, INVALID_ENUM, OUT_OF_RANGE and others; see Validation rules)\n- 401 UNAUTHENTICATED or TOKEN_EXPIRED\n- 403 NOT_ALLOWED (role, scope, school or read-only View-as)\n- 409 rule conflicts (for example SECTION_FULL, ON_HOLD, RECEIPT_IMMUTABLE)\n- 429 RATE_LIMITED (see Retry-After)",
    "parameters": [
     {
      "$ref": "#/components/parameters/request_id"
     },
     {
      "$ref": "#/components/parameters/idempotency"
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "code": {
          "type": "string",
          "description": "Six characters; case and spaces are ignored.",
          "minLength": 6,
          "maxLength": 8
         },
         "external_user_id": {
          "type": "string",
          "description": "The app's own id for the account (hashed by the school, never stored in the clear).",
          "minLength": 3,
          "maxLength": 200
         },
         "display_name": {
          "type": "string",
          "description": "What to show the parent, optional.",
          "maxLength": 40
         }
        },
        "required": [
         "code",
         "external_user_id"
        ],
        "additionalProperties": false
       },
       "example": {
        "code": "string",
        "external_user_id": "2f1c6a0e-8d7b-4c1e-9a55-3b1f0c2d4e6f",
        "display_name": "string"
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Claimed.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "$ref": "#/components/schemas/Claim"
          }
         },
         "required": [
          "data"
         ]
        },
        "example": {
         "data": {
          "claim_token": "string",
          "expires_at": "2026-09-22T09:30:00Z",
          "school": {
           "name": "string"
          },
          "halaqa": {
           "label": "string"
          },
          "teacher": "string",
          "students": [
           {
            "pick_token": "string",
            "first_name": "string",
            "family_initial": "string"
           }
          ]
         },
         "meta": {
          "request_id": "req_01J8Z3X4",
          "generated_at": "2026-09-22T09:30:00Z"
         }
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "429": {
      "$ref": "#/components/responses/TooManyRequests"
     }
    },
    "x-scopes": [
     "partner:links"
    ],
    "x-partner-only": true,
    "security": [
     {
      "partnerKey": []
     }
    ]
   }
  },
  "/partner/links": {
   "post": {
    "tags": [
     "Partner"
    ],
    "summary": "Pick the student",
    "description": "Step two: the student tapped their own name. Makes a pending link and tells every parent; keep the link_id (student_ref). LINK_EXISTS when the student or this account already has a pending or active link; NO_GUARDIAN when the school has no parent on record; CLAIM_EXPIRED after 15 minutes or a second use.\n\n**Who can call:** partnerKey. API keys need scope `partner:links`.\n\n**Request body** (JSON; unknown fields are rejected)\n\n| Field | Type | Rules |\n|---|---|---|\n| `claim_token` | string | Required; 32 to 64 characters. |\n| `pick_token` | string | Required; 32 to 64 characters. |\n\n**Response 201:** `{ data, meta }` where `data` is one PartnerLink.\n\n| Field | Type | Notes |\n|---|---|---|\n| `link_id` | string | Always present; UUID. |\n| `student_ref` | string | Always present; UUID; Equal to link_id: the only id the app ever holds for a student. |\n| `status` | string | Always present; one of `pending`, `active`, `revoked`, `expired`. |\n| `first_name` | string | Always present; at most 60 characters. |\n| `halaqa` | string | May be omitted; may be null; at most 60 characters. |\n| `school` | string | Always present; at most 120 characters. |\n| `teacher` | string | May be omitted; may be null; at most 60 characters. |\n| `program` | string | May be omitted; may be null; at most 20 characters. |\n| `requested_at` | string | Always present; timestamp with offset or Z (RFC 3339). |\n| `expires_at` | string | May be omitted; may be null; timestamp with offset or Z (RFC 3339). |\n| `linked_at` | string | May be omitted; may be null; timestamp with offset or Z (RFC 3339). |\n| `revoked_at` | string | May be omitted; may be null; timestamp with offset or Z (RFC 3339). |\n| `revoked_reason` | string | May be omitted; may be null; parent, school, partner, declined, expired or student. |\n\n**Errors**\n\n- 400 validation (UNKNOWN_FIELD, MISSING_FIELD, INVALID_TYPE, TEXT_TOO_LONG, INVALID_ENUM, OUT_OF_RANGE and others; see Validation rules)\n- 401 UNAUTHENTICATED or TOKEN_EXPIRED\n- 403 NOT_ALLOWED (role, scope, school or read-only View-as)\n- 409 rule conflicts (for example SECTION_FULL, ON_HOLD, RECEIPT_IMMUTABLE)\n- 429 RATE_LIMITED (see Retry-After)",
    "parameters": [
     {
      "$ref": "#/components/parameters/request_id"
     },
     {
      "$ref": "#/components/parameters/idempotency"
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "claim_token": {
          "type": "string",
          "minLength": 32,
          "maxLength": 64
         },
         "pick_token": {
          "type": "string",
          "minLength": 32,
          "maxLength": 64
         }
        },
        "required": [
         "claim_token",
         "pick_token"
        ],
        "additionalProperties": false
       },
       "example": {
        "claim_token": "string",
        "pick_token": "string"
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Pending.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "$ref": "#/components/schemas/PartnerLink"
          }
         },
         "required": [
          "data"
         ]
        },
        "example": {
         "data": {
          "link_id": "2f1c6a0e-8d7b-4c1e-9a55-3b1f0c2d4e6f",
          "student_ref": "2f1c6a0e-8d7b-4c1e-9a55-3b1f0c2d4e6f",
          "status": "pending",
          "first_name": "string",
          "halaqa": "string",
          "school": "string",
          "teacher": "string",
          "program": "string",
          "requested_at": "2026-09-22T09:30:00Z",
          "expires_at": "2026-09-22T09:30:00Z",
          "linked_at": "2026-09-22T09:30:00Z",
          "revoked_at": "2026-09-22T09:30:00Z",
          "revoked_reason": "string"
         },
         "meta": {
          "request_id": "req_01J8Z3X4",
          "generated_at": "2026-09-22T09:30:00Z"
         }
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "429": {
      "$ref": "#/components/responses/TooManyRequests"
     }
    },
    "x-scopes": [
     "partner:links"
    ],
    "x-partner-only": true,
    "security": [
     {
      "partnerKey": []
     }
    ]
   },
   "get": {
    "tags": [
     "Partner"
    ],
    "summary": "My links",
    "description": "Every link of this partner, newest first (at most 200), optionally one status.\n\n**Who can call:** partnerKey. API keys need scope `partner:links`.\n\n**Parameters**\n\n| Parameter | In | Type | Rules |\n|---|---|---|---|\n| `status` | query | string | Optional; one of `pending`, `active`, `revoked`, `expired`. |\n\n**Response 200:** `{ data, meta }` where `data` is a list of PartnerLink.\n\n| Field | Type | Notes |\n|---|---|---|\n| `link_id` | string | Always present; UUID. |\n| `student_ref` | string | Always present; UUID; Equal to link_id: the only id the app ever holds for a student. |\n| `status` | string | Always present; one of `pending`, `active`, `revoked`, `expired`. |\n| `first_name` | string | Always present; at most 60 characters. |\n| `halaqa` | string | May be omitted; may be null; at most 60 characters. |\n| `school` | string | Always present; at most 120 characters. |\n| `teacher` | string | May be omitted; may be null; at most 60 characters. |\n| `program` | string | May be omitted; may be null; at most 20 characters. |\n| `requested_at` | string | Always present; timestamp with offset or Z (RFC 3339). |\n| `expires_at` | string | May be omitted; may be null; timestamp with offset or Z (RFC 3339). |\n| `linked_at` | string | May be omitted; may be null; timestamp with offset or Z (RFC 3339). |\n| `revoked_at` | string | May be omitted; may be null; timestamp with offset or Z (RFC 3339). |\n| `revoked_reason` | string | May be omitted; may be null; parent, school, partner, declined, expired or student. |\n\n**Errors**\n\n- 400 validation (UNKNOWN_FIELD, MISSING_FIELD, INVALID_TYPE, TEXT_TOO_LONG, INVALID_ENUM, OUT_OF_RANGE and others; see Validation rules)\n- 401 UNAUTHENTICATED or TOKEN_EXPIRED\n- 403 NOT_ALLOWED (role, scope, school or read-only View-as)\n- 429 RATE_LIMITED (see Retry-After)",
    "parameters": [
     {
      "$ref": "#/components/parameters/request_id"
     },
     {
      "name": "status",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "pending",
        "active",
        "revoked",
        "expired"
       ]
      }
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/PartnerLink"
           }
          }
         },
         "required": [
          "data"
         ]
        },
        "example": {
         "data": [
          {
           "link_id": "2f1c6a0e-8d7b-4c1e-9a55-3b1f0c2d4e6f",
           "student_ref": "2f1c6a0e-8d7b-4c1e-9a55-3b1f0c2d4e6f",
           "status": "pending",
           "first_name": "string",
           "halaqa": "string",
           "school": "string",
           "teacher": "string",
           "program": "string",
           "requested_at": "2026-09-22T09:30:00Z",
           "expires_at": "2026-09-22T09:30:00Z",
           "linked_at": "2026-09-22T09:30:00Z",
           "revoked_at": "2026-09-22T09:30:00Z",
           "revoked_reason": "string"
          }
         ],
         "meta": {
          "request_id": "req_01J8Z3X4",
          "generated_at": "2026-09-22T09:30:00Z"
         }
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "429": {
      "$ref": "#/components/responses/TooManyRequests"
     }
    },
    "x-scopes": [
     "partner:links"
    ],
    "x-partner-only": true,
    "security": [
     {
      "partnerKey": []
     }
    ]
   }
  },
  "/partner/links/{student_ref}": {
   "get": {
    "tags": [
     "Partner"
    ],
    "summary": "One link",
    "description": "Its state now: the app reads this after a missed webhook. NOT_FOUND for a link that is not this partner's.\n\n**Who can call:** partnerKey. API keys need scope `partner:links`.\n\n**Parameters**\n\n| Parameter | In | Type | Rules |\n|---|---|---|---|\n| `student_ref` | path | string | Required; UUID; at most 40 characters. |\n\n**Response 200:** `{ data, meta }` where `data` is one PartnerLink.\n\n| Field | Type | Notes |\n|---|---|---|\n| `link_id` | string | Always present; UUID. |\n| `student_ref` | string | Always present; UUID; Equal to link_id: the only id the app ever holds for a student. |\n| `status` | string | Always present; one of `pending`, `active`, `revoked`, `expired`. |\n| `first_name` | string | Always present; at most 60 characters. |\n| `halaqa` | string | May be omitted; may be null; at most 60 characters. |\n| `school` | string | Always present; at most 120 characters. |\n| `teacher` | string | May be omitted; may be null; at most 60 characters. |\n| `program` | string | May be omitted; may be null; at most 20 characters. |\n| `requested_at` | string | Always present; timestamp with offset or Z (RFC 3339). |\n| `expires_at` | string | May be omitted; may be null; timestamp with offset or Z (RFC 3339). |\n| `linked_at` | string | May be omitted; may be null; timestamp with offset or Z (RFC 3339). |\n| `revoked_at` | string | May be omitted; may be null; timestamp with offset or Z (RFC 3339). |\n| `revoked_reason` | string | May be omitted; may be null; parent, school, partner, declined, expired or student. |\n\n**Errors**\n\n- 400 validation (UNKNOWN_FIELD, MISSING_FIELD, INVALID_TYPE, TEXT_TOO_LONG, INVALID_ENUM, OUT_OF_RANGE and others; see Validation rules)\n- 401 UNAUTHENTICATED or TOKEN_EXPIRED\n- 403 NOT_ALLOWED (role, scope, school or read-only View-as)\n- 404 NOT_FOUND (missing, or not visible to this caller)\n- 429 RATE_LIMITED (see Retry-After)",
    "parameters": [
     {
      "$ref": "#/components/parameters/request_id"
     },
     {
      "name": "student_ref",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "maxLength": 40
      },
      "description": "The link id the app received when the student picked their name."
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "$ref": "#/components/schemas/PartnerLink"
          }
         },
         "required": [
          "data"
         ]
        },
        "example": {
         "data": {
          "link_id": "2f1c6a0e-8d7b-4c1e-9a55-3b1f0c2d4e6f",
          "student_ref": "2f1c6a0e-8d7b-4c1e-9a55-3b1f0c2d4e6f",
          "status": "pending",
          "first_name": "string",
          "halaqa": "string",
          "school": "string",
          "teacher": "string",
          "program": "string",
          "requested_at": "2026-09-22T09:30:00Z",
          "expires_at": "2026-09-22T09:30:00Z",
          "linked_at": "2026-09-22T09:30:00Z",
          "revoked_at": "2026-09-22T09:30:00Z",
          "revoked_reason": "string"
         },
         "meta": {
          "request_id": "req_01J8Z3X4",
          "generated_at": "2026-09-22T09:30:00Z"
         }
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "429": {
      "$ref": "#/components/responses/TooManyRequests"
     }
    },
    "x-scopes": [
     "partner:links"
    ],
    "x-partner-only": true,
    "security": [
     {
      "partnerKey": []
     }
    ]
   },
   "delete": {
    "tags": [
     "Partner"
    ],
    "summary": "End a link",
    "description": "The student withdrew before the parent answered, or consent was withdrawn in the app; delete_practice also removes the home practice the app sent. The school is told.\n\n**Who can call:** partnerKey. API keys need scope `partner:links`.\n\n**Parameters**\n\n| Parameter | In | Type | Rules |\n|---|---|---|---|\n| `student_ref` | path | string | Required; UUID; at most 40 characters. |\n| `delete_practice` | query | boolean | Optional. |\n\n**Response 200:** `{ data, meta }` where `data` is one PartnerLink.\n\n| Field | Type | Notes |\n|---|---|---|\n| `link_id` | string | Always present; UUID. |\n| `student_ref` | string | Always present; UUID; Equal to link_id: the only id the app ever holds for a student. |\n| `status` | string | Always present; one of `pending`, `active`, `revoked`, `expired`. |\n| `first_name` | string | Always present; at most 60 characters. |\n| `halaqa` | string | May be omitted; may be null; at most 60 characters. |\n| `school` | string | Always present; at most 120 characters. |\n| `teacher` | string | May be omitted; may be null; at most 60 characters. |\n| `program` | string | May be omitted; may be null; at most 20 characters. |\n| `requested_at` | string | Always present; timestamp with offset or Z (RFC 3339). |\n| `expires_at` | string | May be omitted; may be null; timestamp with offset or Z (RFC 3339). |\n| `linked_at` | string | May be omitted; may be null; timestamp with offset or Z (RFC 3339). |\n| `revoked_at` | string | May be omitted; may be null; timestamp with offset or Z (RFC 3339). |\n| `revoked_reason` | string | May be omitted; may be null; parent, school, partner, declined, expired or student. |\n\n**Errors**\n\n- 400 validation (UNKNOWN_FIELD, MISSING_FIELD, INVALID_TYPE, TEXT_TOO_LONG, INVALID_ENUM, OUT_OF_RANGE and others; see Validation rules)\n- 401 UNAUTHENTICATED or TOKEN_EXPIRED\n- 403 NOT_ALLOWED (role, scope, school or read-only View-as)\n- 404 NOT_FOUND (missing, or not visible to this caller)\n- 409 rule conflicts (for example SECTION_FULL, ON_HOLD, RECEIPT_IMMUTABLE)\n- 429 RATE_LIMITED (see Retry-After)",
    "parameters": [
     {
      "$ref": "#/components/parameters/request_id"
     },
     {
      "$ref": "#/components/parameters/idempotency"
     },
     {
      "name": "student_ref",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "maxLength": 40
      },
      "description": "The link id the app received when the student picked their name."
     },
     {
      "name": "delete_practice",
      "in": "query",
      "schema": {
       "type": "boolean"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "$ref": "#/components/schemas/PartnerLink"
          }
         },
         "required": [
          "data"
         ]
        },
        "example": {
         "data": {
          "link_id": "2f1c6a0e-8d7b-4c1e-9a55-3b1f0c2d4e6f",
          "student_ref": "2f1c6a0e-8d7b-4c1e-9a55-3b1f0c2d4e6f",
          "status": "pending",
          "first_name": "string",
          "halaqa": "string",
          "school": "string",
          "teacher": "string",
          "program": "string",
          "requested_at": "2026-09-22T09:30:00Z",
          "expires_at": "2026-09-22T09:30:00Z",
          "linked_at": "2026-09-22T09:30:00Z",
          "revoked_at": "2026-09-22T09:30:00Z",
          "revoked_reason": "string"
         },
         "meta": {
          "request_id": "req_01J8Z3X4",
          "generated_at": "2026-09-22T09:30:00Z"
         }
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "429": {
      "$ref": "#/components/responses/TooManyRequests"
     }
    },
    "x-scopes": [
     "partner:links"
    ],
    "x-partner-only": true,
    "security": [
     {
      "partnerKey": []
     }
    ]
   }
  },
  "/partner/homework": {
   "get": {
    "tags": [
     "Partner"
    ],
    "summary": "Open homework",
    "description": "The linked student's open homework and recent grades, to rebuild the app's Home card after a missed webhook. NOT_LINKED or LINK_PENDING for the account.\n\n**Who can call:** partnerKey. API keys need scope `partner:links`.\n\n**Parameters**\n\n| Parameter | In | Type | Rules |\n|---|---|---|---|\n| `external_user_id` | query | string | Required; 3 to 200 characters. |\n\n**Response 200:** `{ data, meta }` where `data` is one PartnerHomework.\n\n| Field | Type | Notes |\n|---|---|---|\n| `student_ref` | string | Always present; UUID. |\n| `first_name` | string | Always present; at most 60 characters. |\n| `halaqa` | string | May be omitted; may be null; at most 60 characters. |\n| `teacher` | string | May be omitted; may be null; at most 60 characters. |\n| `program` | string | May be omitted; may be null; at most 20 characters. |\n| `as_of` | string | Always present; timestamp with offset or Z (RFC 3339). |\n| `lessons` | array of PartnerLesson | Always present. |\n| `recent` | array of PartnerLesson | Always present. |\n\n**Errors**\n\n- 400 validation (UNKNOWN_FIELD, MISSING_FIELD, INVALID_TYPE, TEXT_TOO_LONG, INVALID_ENUM, OUT_OF_RANGE and others; see Validation rules)\n- 401 UNAUTHENTICATED or TOKEN_EXPIRED\n- 403 NOT_ALLOWED (role, scope, school or read-only View-as)\n- 429 RATE_LIMITED (see Retry-After)",
    "parameters": [
     {
      "$ref": "#/components/parameters/request_id"
     },
     {
      "name": "external_user_id",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string",
       "minLength": 3,
       "maxLength": 200
      }
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "$ref": "#/components/schemas/PartnerHomework"
          }
         },
         "required": [
          "data"
         ]
        },
        "example": {
         "data": {
          "student_ref": "2f1c6a0e-8d7b-4c1e-9a55-3b1f0c2d4e6f",
          "first_name": "string",
          "halaqa": "string",
          "teacher": "string",
          "program": "string",
          "as_of": "2026-09-22T09:30:00Z",
          "lessons": [
           {
            "lesson_id": "2f1c6a0e-8d7b-4c1e-9a55-3b1f0c2d4e6f",
            "on": "2026-09-01",
            "part": "sabaq",
            "kind": "range",
            "surah": 1,
            "surah_name": "string",
            "ayah_from": 1,
            "ayah_to": 1,
            "juz_from": 1,
            "juz_to": 1,
            "qaida_lesson": 1,
            "riwayah": "string",
            "due_date": "2026-09-01",
            "status": "assigned",
            "result": "pending",
            "grade": "mumtaz",
            "remark": "string",
            "graded_at": "2026-09-22T09:30:00Z",
            "text": [
             {
              "ayah": 1,
              "text": "string"
             }
            ]
           }
          ],
          "recent": [
           {
            "lesson_id": "2f1c6a0e-8d7b-4c1e-9a55-3b1f0c2d4e6f",
            "on": "2026-09-01",
            "part": "sabaq",
            "kind": "range",
            "surah": 1,
            "surah_name": "string",
            "ayah_from": 1,
            "ayah_to": 1,
            "juz_from": 1,
            "juz_to": 1,
            "qaida_lesson": 1,
            "riwayah": "string",
            "due_date": "2026-09-01",
            "status": "assigned",
            "result": "pending",
            "grade": "mumtaz",
            "remark": "string",
            "graded_at": "2026-09-22T09:30:00Z",
            "text": [
             {
              "ayah": 1,
              "text": "string"
             }
            ]
           }
          ]
         },
         "meta": {
          "request_id": "req_01J8Z3X4",
          "generated_at": "2026-09-22T09:30:00Z"
         }
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "429": {
      "$ref": "#/components/responses/TooManyRequests"
     }
    },
    "x-scopes": [
     "partner:links"
    ],
    "x-partner-only": true,
    "security": [
     {
      "partnerKey": []
     }
    ]
   }
  },
  "/partner/recitations": {
   "post": {
    "tags": [
     "Partner"
    ],
    "summary": "Start a recitation upload",
    "description": "The student recorded an open homework part (or a juz test). Announce the file: content type, size and length; the answer carries one upload link per part of at most 5 MB (8 parts, 40 MB in all). PUT each part's bytes to its link with the same Content-Type, then submit. ASSIGNMENT_CLOSED unless the part is assigned or was graded repeat; RECITATION_TOO_LONG past the school's limit (20 minutes by default, 60 for a juz test); RECITATION_TOO_LARGE past 40 MB; CONTENT_TYPE_INVALID outside audio/mp4, aac, ogg, webm, mpeg.\n\n**Who can call:** partnerKey. API keys need scope `partner:recitations`.\n\n**Request body** (JSON; unknown fields are rejected)\n\n| Field | Type | Rules |\n|---|---|---|\n| `external_user_id` | string | Required; 3 to 200 characters. |\n| `lesson_id` | string | Required; UUID; at most 40 characters. |\n| `content_type` | string | Required; one of `audio/mp4`, `audio/aac`, `audio/ogg`, `audio/webm`, `audio/mpeg`. |\n| `bytes` | integer | Required; from 1 to 41943040. |\n| `duration_seconds` | integer | Required; from 1 to 3600. |\n| `parts` | integer | Optional; from 1 to 8; ceil(bytes / 5 MB) unless given. |\n| `kind` | string | Optional; one of `student`, `juz_test`. |\n\n**Response 201:** `{ data, meta }` where `data` is one RecitationStart.\n\n| Field | Type | Notes |\n|---|---|---|\n| `recitation_id` | string | Always present; UUID. |\n| `student_ref` | string | Always present; UUID. |\n| `attempt` | integer | Always present. |\n| `upload` | object | Always present. |\n\n**Errors**\n\n- 400 validation (UNKNOWN_FIELD, MISSING_FIELD, INVALID_TYPE, TEXT_TOO_LONG, INVALID_ENUM, OUT_OF_RANGE and others; see Validation rules)\n- 401 UNAUTHENTICATED or TOKEN_EXPIRED\n- 403 NOT_ALLOWED (role, scope, school or read-only View-as)\n- 409 rule conflicts (for example SECTION_FULL, ON_HOLD, RECEIPT_IMMUTABLE)\n- 429 RATE_LIMITED (see Retry-After)",
    "parameters": [
     {
      "$ref": "#/components/parameters/request_id"
     },
     {
      "$ref": "#/components/parameters/idempotency"
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "external_user_id": {
          "type": "string",
          "minLength": 3,
          "maxLength": 200
         },
         "lesson_id": {
          "type": "string",
          "format": "uuid",
          "maxLength": 40
         },
         "content_type": {
          "type": "string",
          "enum": [
           "audio/mp4",
           "audio/aac",
           "audio/ogg",
           "audio/webm",
           "audio/mpeg"
          ]
         },
         "bytes": {
          "type": "integer",
          "minimum": 1,
          "maximum": 41943040
         },
         "duration_seconds": {
          "type": "integer",
          "minimum": 1,
          "maximum": 3600
         },
         "parts": {
          "type": "integer",
          "minimum": 1,
          "maximum": 8,
          "description": "ceil(bytes / 5 MB) unless given."
         },
         "kind": {
          "type": "string",
          "enum": [
           "student",
           "juz_test"
          ]
         }
        },
        "required": [
         "external_user_id",
         "lesson_id",
         "content_type",
         "bytes",
         "duration_seconds"
        ],
        "additionalProperties": false
       },
       "example": {
        "external_user_id": "2f1c6a0e-8d7b-4c1e-9a55-3b1f0c2d4e6f",
        "lesson_id": "2f1c6a0e-8d7b-4c1e-9a55-3b1f0c2d4e6f",
        "content_type": "audio/mp4",
        "bytes": 1,
        "duration_seconds": 1,
        "parts": 1,
        "kind": "student"
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Started.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "$ref": "#/components/schemas/RecitationStart"
          }
         },
         "required": [
          "data"
         ]
        },
        "example": {
         "data": {
          "recitation_id": "2f1c6a0e-8d7b-4c1e-9a55-3b1f0c2d4e6f",
          "student_ref": "2f1c6a0e-8d7b-4c1e-9a55-3b1f0c2d4e6f",
          "attempt": 1,
          "upload": {
           "kind": "single",
           "part_bytes": 1,
           "parts": [
            {
             "part_number": 1,
             "url": "https://erp.example.pk/samas/hook",
             "max_bytes": 1
            }
           ],
           "expires_at": "2026-09-22T09:30:00Z"
          }
         },
         "meta": {
          "request_id": "req_01J8Z3X4",
          "generated_at": "2026-09-22T09:30:00Z"
         }
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "429": {
      "$ref": "#/components/responses/TooManyRequests"
     }
    },
    "x-scopes": [
     "partner:recitations"
    ],
    "x-partner-only": true,
    "security": [
     {
      "partnerKey": []
     }
    ]
   },
   "get": {
    "tags": [
     "Partner"
    ],
    "summary": "The student's recitations",
    "description": "Newest first (at most 50), with feedback where reviewed; to rebuild the app's list.\n\n**Who can call:** partnerKey. API keys need scope `partner:recitations`.\n\n**Parameters**\n\n| Parameter | In | Type | Rules |\n|---|---|---|---|\n| `external_user_id` | query | string | Required; 3 to 200 characters. |\n\n**Response 200:** `{ data, meta }` where `data` is a list of PartnerRecitation.\n\n| Field | Type | Notes |\n|---|---|---|\n| `recitation_id` | string | Always present; UUID. |\n| `student_ref` | string | Always present; UUID. |\n| `lesson_id` | string | May be omitted; may be null; UUID. |\n| `kind` | string | Always present; one of `student`, `model`, `juz_test`. |\n| `attempt` | integer | Always present. |\n| `status` | string | Always present; one of `uploading`, `submitted`, `reviewed`, `deleted`. |\n| `surah` | integer | May be omitted; may be null. |\n| `surah_name` | string | May be omitted; may be null. |\n| `ayah_from` | integer | May be omitted; may be null. |\n| `ayah_to` | integer | May be omitted; may be null. |\n| `juz` | integer | May be omitted; may be null. |\n| `duration_seconds` | integer | Always present. |\n| `submitted_at` | string | May be omitted; may be null; timestamp with offset or Z (RFC 3339). |\n| `reviewed_at` | string | May be omitted; may be null; timestamp with offset or Z (RFC 3339). |\n| `teacher` | string | May be omitted; may be null; at most 60 characters. |\n| `grade` | string | May be omitted; may be null. |\n| `remark` | string | May be omitted; may be null. |\n| `can_re_record` | boolean | Always present. |\n| `notes` | array of object | Always present. |\n| `model` | object | May be omitted. |\n\n**Errors**\n\n- 400 validation (UNKNOWN_FIELD, MISSING_FIELD, INVALID_TYPE, TEXT_TOO_LONG, INVALID_ENUM, OUT_OF_RANGE and others; see Validation rules)\n- 401 UNAUTHENTICATED or TOKEN_EXPIRED\n- 403 NOT_ALLOWED (role, scope, school or read-only View-as)\n- 429 RATE_LIMITED (see Retry-After)",
    "parameters": [
     {
      "$ref": "#/components/parameters/request_id"
     },
     {
      "name": "external_user_id",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string",
       "minLength": 3,
       "maxLength": 200
      }
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/PartnerRecitation"
           }
          }
         },
         "required": [
          "data"
         ]
        },
        "example": {
         "data": [
          {
           "recitation_id": "2f1c6a0e-8d7b-4c1e-9a55-3b1f0c2d4e6f",
           "student_ref": "2f1c6a0e-8d7b-4c1e-9a55-3b1f0c2d4e6f",
           "lesson_id": "2f1c6a0e-8d7b-4c1e-9a55-3b1f0c2d4e6f",
           "kind": "student",
           "attempt": 1,
           "status": "uploading",
           "surah": 1,
           "surah_name": "string",
           "ayah_from": 1,
           "ayah_to": 1,
           "juz": 1,
           "duration_seconds": 1,
           "submitted_at": "2026-09-22T09:30:00Z",
           "reviewed_at": "2026-09-22T09:30:00Z",
           "teacher": "string",
           "grade": "string",
           "remark": "string",
           "can_re_record": true,
           "notes": [
            {
             "ayah": 1,
             "word_index": 1,
             "word": "string",
             "category": "string",
             "text": "string",
             "at_seconds": 1
            }
           ],
           "model": {
            "recitation_id": "2f1c6a0e-8d7b-4c1e-9a55-3b1f0c2d4e6f",
            "duration_seconds": 1,
            "available": true
           }
          }
         ],
         "meta": {
          "request_id": "req_01J8Z3X4",
          "generated_at": "2026-09-22T09:30:00Z"
         }
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "429": {
      "$ref": "#/components/responses/TooManyRequests"
     }
    },
    "x-scopes": [
     "partner:recitations"
    ],
    "x-partner-only": true,
    "security": [
     {
      "partnerKey": []
     }
    ]
   }
  },
  "/partner/recitations/{recitation_id}/submit": {
   "post": {
    "tags": [
     "Partner"
    ],
    "summary": "Submit the recitation",
    "description": "After every part is uploaded: the school joins the parts, hashes the file and checks the checksum (CHECKSUM_MISMATCH, UPLOAD_INCOMPLETE). ayah_marks say where each ayah starts in the recording so the teacher can jump to it. The recording enters the teacher's inbox.\n\n**Who can call:** partnerKey. API keys need scope `partner:recitations`.\n\n**Parameters**\n\n| Parameter | In | Type | Rules |\n|---|---|---|---|\n| `recitation_id` | path | string | Required; UUID; at most 40 characters. |\n\n**Request body** (JSON; unknown fields are rejected)\n\n| Field | Type | Rules |\n|---|---|---|\n| `external_user_id` | string | Required; 3 to 200 characters. |\n| `checksum_sha256` | string | Required; pattern `^[0-9a-fA-F]{64}$`; at most 64 characters. |\n| `ayah_marks` | array of object | Optional; at most 300 items. |\n\n**Response 200:** `{ data, meta }` where `data` is one PartnerRecitation.\n\n| Field | Type | Notes |\n|---|---|---|\n| `recitation_id` | string | Always present; UUID. |\n| `student_ref` | string | Always present; UUID. |\n| `lesson_id` | string | May be omitted; may be null; UUID. |\n| `kind` | string | Always present; one of `student`, `model`, `juz_test`. |\n| `attempt` | integer | Always present. |\n| `status` | string | Always present; one of `uploading`, `submitted`, `reviewed`, `deleted`. |\n| `surah` | integer | May be omitted; may be null. |\n| `surah_name` | string | May be omitted; may be null. |\n| `ayah_from` | integer | May be omitted; may be null. |\n| `ayah_to` | integer | May be omitted; may be null. |\n| `juz` | integer | May be omitted; may be null. |\n| `duration_seconds` | integer | Always present. |\n| `submitted_at` | string | May be omitted; may be null; timestamp with offset or Z (RFC 3339). |\n| `reviewed_at` | string | May be omitted; may be null; timestamp with offset or Z (RFC 3339). |\n| `teacher` | string | May be omitted; may be null; at most 60 characters. |\n| `grade` | string | May be omitted; may be null. |\n| `remark` | string | May be omitted; may be null. |\n| `can_re_record` | boolean | Always present. |\n| `notes` | array of object | Always present. |\n| `model` | object | May be omitted. |\n\n**Errors**\n\n- 400 validation (UNKNOWN_FIELD, MISSING_FIELD, INVALID_TYPE, TEXT_TOO_LONG, INVALID_ENUM, OUT_OF_RANGE and others; see Validation rules)\n- 401 UNAUTHENTICATED or TOKEN_EXPIRED\n- 403 NOT_ALLOWED (role, scope, school or read-only View-as)\n- 404 NOT_FOUND (missing, or not visible to this caller)\n- 409 rule conflicts (for example SECTION_FULL, ON_HOLD, RECEIPT_IMMUTABLE)\n- 429 RATE_LIMITED (see Retry-After)",
    "parameters": [
     {
      "$ref": "#/components/parameters/request_id"
     },
     {
      "$ref": "#/components/parameters/idempotency"
     },
     {
      "name": "recitation_id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "maxLength": 40
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "external_user_id": {
          "type": "string",
          "minLength": 3,
          "maxLength": 200
         },
         "checksum_sha256": {
          "type": "string",
          "pattern": "^[0-9a-fA-F]{64}$",
          "maxLength": 64
         },
         "ayah_marks": {
          "type": "array",
          "items": {
           "type": "object",
           "properties": {
            "ayah": {
             "type": "integer",
             "minimum": 1,
             "maximum": 286
            },
            "at_seconds": {
             "type": "number",
             "minimum": 0,
             "maximum": 3600
            }
           },
           "required": [
            "ayah",
            "at_seconds"
           ],
           "additionalProperties": false
          },
          "maxItems": 300
         }
        },
        "required": [
         "external_user_id",
         "checksum_sha256"
        ],
        "additionalProperties": false
       },
       "example": {
        "external_user_id": "2f1c6a0e-8d7b-4c1e-9a55-3b1f0c2d4e6f",
        "checksum_sha256": "string",
        "ayah_marks": [
         {
          "ayah": 1,
          "at_seconds": 1.5
         }
        ]
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "$ref": "#/components/schemas/PartnerRecitation"
          }
         },
         "required": [
          "data"
         ]
        },
        "example": {
         "data": {
          "recitation_id": "2f1c6a0e-8d7b-4c1e-9a55-3b1f0c2d4e6f",
          "student_ref": "2f1c6a0e-8d7b-4c1e-9a55-3b1f0c2d4e6f",
          "lesson_id": "2f1c6a0e-8d7b-4c1e-9a55-3b1f0c2d4e6f",
          "kind": "student",
          "attempt": 1,
          "status": "uploading",
          "surah": 1,
          "surah_name": "string",
          "ayah_from": 1,
          "ayah_to": 1,
          "juz": 1,
          "duration_seconds": 1,
          "submitted_at": "2026-09-22T09:30:00Z",
          "reviewed_at": "2026-09-22T09:30:00Z",
          "teacher": "string",
          "grade": "string",
          "remark": "string",
          "can_re_record": true,
          "notes": [
           {
            "ayah": 1,
            "word_index": 1,
            "word": "string",
            "category": "string",
            "text": "string",
            "at_seconds": 1
           }
          ],
          "model": {
           "recitation_id": "2f1c6a0e-8d7b-4c1e-9a55-3b1f0c2d4e6f",
           "duration_seconds": 1,
           "available": true
          }
         },
         "meta": {
          "request_id": "req_01J8Z3X4",
          "generated_at": "2026-09-22T09:30:00Z"
         }
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "429": {
      "$ref": "#/components/responses/TooManyRequests"
     }
    },
    "x-scopes": [
     "partner:recitations"
    ],
    "x-partner-only": true,
    "security": [
     {
      "partnerKey": []
     }
    ]
   }
  },
  "/partner/recitations/{recitation_id}/feedback": {
   "get": {
    "tags": [
     "Partner"
    ],
    "summary": "The teacher's feedback",
    "description": "The review of one recitation: grade, remark, notes pinned to words with the moment in the recording, whether a new attempt is allowed, and the model reading if there is one. Also sent as the recitation.reviewed webhook.\n\n**Who can call:** partnerKey. API keys need scope `partner:recitations`.\n\n**Parameters**\n\n| Parameter | In | Type | Rules |\n|---|---|---|---|\n| `recitation_id` | path | string | Required; UUID; at most 40 characters. |\n| `external_user_id` | query | string | Required; 3 to 200 characters. |\n\n**Response 200:** `{ data, meta }` where `data` is one PartnerRecitation.\n\n| Field | Type | Notes |\n|---|---|---|\n| `recitation_id` | string | Always present; UUID. |\n| `student_ref` | string | Always present; UUID. |\n| `lesson_id` | string | May be omitted; may be null; UUID. |\n| `kind` | string | Always present; one of `student`, `model`, `juz_test`. |\n| `attempt` | integer | Always present. |\n| `status` | string | Always present; one of `uploading`, `submitted`, `reviewed`, `deleted`. |\n| `surah` | integer | May be omitted; may be null. |\n| `surah_name` | string | May be omitted; may be null. |\n| `ayah_from` | integer | May be omitted; may be null. |\n| `ayah_to` | integer | May be omitted; may be null. |\n| `juz` | integer | May be omitted; may be null. |\n| `duration_seconds` | integer | Always present. |\n| `submitted_at` | string | May be omitted; may be null; timestamp with offset or Z (RFC 3339). |\n| `reviewed_at` | string | May be omitted; may be null; timestamp with offset or Z (RFC 3339). |\n| `teacher` | string | May be omitted; may be null; at most 60 characters. |\n| `grade` | string | May be omitted; may be null. |\n| `remark` | string | May be omitted; may be null. |\n| `can_re_record` | boolean | Always present. |\n| `notes` | array of object | Always present. |\n| `model` | object | May be omitted. |\n\n**Errors**\n\n- 400 validation (UNKNOWN_FIELD, MISSING_FIELD, INVALID_TYPE, TEXT_TOO_LONG, INVALID_ENUM, OUT_OF_RANGE and others; see Validation rules)\n- 401 UNAUTHENTICATED or TOKEN_EXPIRED\n- 403 NOT_ALLOWED (role, scope, school or read-only View-as)\n- 404 NOT_FOUND (missing, or not visible to this caller)\n- 429 RATE_LIMITED (see Retry-After)",
    "parameters": [
     {
      "$ref": "#/components/parameters/request_id"
     },
     {
      "name": "recitation_id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "maxLength": 40
      }
     },
     {
      "name": "external_user_id",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string",
       "minLength": 3,
       "maxLength": 200
      }
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "$ref": "#/components/schemas/PartnerRecitation"
          }
         },
         "required": [
          "data"
         ]
        },
        "example": {
         "data": {
          "recitation_id": "2f1c6a0e-8d7b-4c1e-9a55-3b1f0c2d4e6f",
          "student_ref": "2f1c6a0e-8d7b-4c1e-9a55-3b1f0c2d4e6f",
          "lesson_id": "2f1c6a0e-8d7b-4c1e-9a55-3b1f0c2d4e6f",
          "kind": "student",
          "attempt": 1,
          "status": "uploading",
          "surah": 1,
          "surah_name": "string",
          "ayah_from": 1,
          "ayah_to": 1,
          "juz": 1,
          "duration_seconds": 1,
          "submitted_at": "2026-09-22T09:30:00Z",
          "reviewed_at": "2026-09-22T09:30:00Z",
          "teacher": "string",
          "grade": "string",
          "remark": "string",
          "can_re_record": true,
          "notes": [
           {
            "ayah": 1,
            "word_index": 1,
            "word": "string",
            "category": "string",
            "text": "string",
            "at_seconds": 1
           }
          ],
          "model": {
           "recitation_id": "2f1c6a0e-8d7b-4c1e-9a55-3b1f0c2d4e6f",
           "duration_seconds": 1,
           "available": true
          }
         },
         "meta": {
          "request_id": "req_01J8Z3X4",
          "generated_at": "2026-09-22T09:30:00Z"
         }
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "429": {
      "$ref": "#/components/responses/TooManyRequests"
     }
    },
    "x-scopes": [
     "partner:recitations"
    ],
    "x-partner-only": true,
    "security": [
     {
      "partnerKey": []
     }
    ]
   }
  },
  "/partner/recitations/{recitation_id}/play": {
   "get": {
    "tags": [
     "Partner"
    ],
    "summary": "Play a recording",
    "description": "A 10-minute streaming link for the student's own recording or the teacher's model reading; the play is logged. NOT_FOUND once the school's retention has removed the audio.\n\n**Who can call:** partnerKey. API keys need scope `partner:recitations`.\n\n**Parameters**\n\n| Parameter | In | Type | Rules |\n|---|---|---|---|\n| `recitation_id` | path | string | Required; UUID; at most 40 characters. |\n| `external_user_id` | query | string | Required; 3 to 200 characters. |\n\n**Response 200:** `{ data, meta }` where `data` is one PartnerPlayLink.\n\n| Field | Type | Notes |\n|---|---|---|\n| `url` | string | Always present; https URL. |\n| `expires_at` | string | Always present; timestamp with offset or Z (RFC 3339). |\n| `content_type` | string | Always present; at most 20 characters. |\n| `duration_seconds` | integer | Always present. |\n\n**Errors**\n\n- 400 validation (UNKNOWN_FIELD, MISSING_FIELD, INVALID_TYPE, TEXT_TOO_LONG, INVALID_ENUM, OUT_OF_RANGE and others; see Validation rules)\n- 401 UNAUTHENTICATED or TOKEN_EXPIRED\n- 403 NOT_ALLOWED (role, scope, school or read-only View-as)\n- 404 NOT_FOUND (missing, or not visible to this caller)\n- 429 RATE_LIMITED (see Retry-After)",
    "parameters": [
     {
      "$ref": "#/components/parameters/request_id"
     },
     {
      "name": "recitation_id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "maxLength": 40
      }
     },
     {
      "name": "external_user_id",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string",
       "minLength": 3,
       "maxLength": 200
      }
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "$ref": "#/components/schemas/PartnerPlayLink"
          }
         },
         "required": [
          "data"
         ]
        },
        "example": {
         "data": {
          "url": "https://erp.example.pk/samas/hook",
          "expires_at": "2026-09-22T09:30:00Z",
          "content_type": "string",
          "duration_seconds": 1
         },
         "meta": {
          "request_id": "req_01J8Z3X4",
          "generated_at": "2026-09-22T09:30:00Z"
         }
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "429": {
      "$ref": "#/components/responses/TooManyRequests"
     }
    },
    "x-scopes": [
     "partner:recitations"
    ],
    "x-partner-only": true,
    "security": [
     {
      "partnerKey": []
     }
    ]
   }
  },
  "/partner/practice": {
   "post": {
    "tags": [
     "Partner"
    ],
    "summary": "Post home practice",
    "description": "Up to 31 days of what one linked student read at home; a day is the unit and a repeat replaces it. NOT_LINKED or LINK_PENDING for the account; AYAH_INVALID for an ayah outside the Kufan count; DATE_TOO_OLD past 90 days or in the future.\n\n**Who can call:** partnerKey. API keys need scope `partner:practice`.\n\n**Request body** (JSON; unknown fields are rejected)\n\n| Field | Type | Rules |\n|---|---|---|\n| `external_user_id` | string | Required; 3 to 200 characters. |\n| `days` | array of PracticeDay | Required; at most 31 items. |\n\n**Response 200:** `{ data, meta }` where `data` is one PracticeAccepted.\n\n| Field | Type | Notes |\n|---|---|---|\n| `accepted` | integer | Always present. |\n| `replaced` | integer | Always present. |\n| `student_ref` | string | Always present; UUID. |\n\n**Errors**\n\n- 400 validation (UNKNOWN_FIELD, MISSING_FIELD, INVALID_TYPE, TEXT_TOO_LONG, INVALID_ENUM, OUT_OF_RANGE and others; see Validation rules)\n- 401 UNAUTHENTICATED or TOKEN_EXPIRED\n- 403 NOT_ALLOWED (role, scope, school or read-only View-as)\n- 409 rule conflicts (for example SECTION_FULL, ON_HOLD, RECEIPT_IMMUTABLE)\n- 429 RATE_LIMITED (see Retry-After)",
    "parameters": [
     {
      "$ref": "#/components/parameters/request_id"
     },
     {
      "$ref": "#/components/parameters/idempotency"
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "external_user_id": {
          "type": "string",
          "minLength": 3,
          "maxLength": 200
         },
         "days": {
          "type": "array",
          "items": {
           "$ref": "#/components/schemas/PracticeDay"
          },
          "minItems": 1,
          "maxItems": 31
         }
        },
        "required": [
         "external_user_id",
         "days"
        ],
        "additionalProperties": false
       },
       "example": {
        "external_user_id": "2f1c6a0e-8d7b-4c1e-9a55-3b1f0c2d4e6f",
        "days": [
         {
          "on_date": "2026-09-01",
          "ayahs": [
           [
            1
           ]
          ],
          "minutes_estimated": 1,
          "source_id": "2f1c6a0e-8d7b-4c1e-9a55-3b1f0c2d4e6f"
         }
        ]
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "$ref": "#/components/schemas/PracticeAccepted"
          }
         },
         "required": [
          "data"
         ]
        },
        "example": {
         "data": {
          "accepted": 1,
          "replaced": 1,
          "student_ref": "2f1c6a0e-8d7b-4c1e-9a55-3b1f0c2d4e6f"
         },
         "meta": {
          "request_id": "req_01J8Z3X4",
          "generated_at": "2026-09-22T09:30:00Z"
         }
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "429": {
      "$ref": "#/components/responses/TooManyRequests"
     }
    },
    "x-scopes": [
     "partner:practice"
    ],
    "x-partner-only": true,
    "security": [
     {
      "partnerKey": []
     }
    ]
   }
  },
  "/partner/live/sessions": {
   "get": {
    "tags": [
     "Partner"
    ],
    "summary": "Live sessions",
    "description": "The linked student's live sessions: live now, scheduled in the next 7 days, and the last 10 that ended, newest first within each group. can_join and join_blocked say whether Join works. Errors: NOT_LINKED, LINK_PENDING, LIVE_ADDON_OFF, LIVE_DISABLED, LIVE_NOT_ON_ROSTER, LIVE_NOT_STARTED, LIVE_ENDED, LIVE_CANCELLED, LIVE_NO_CONSENT, LIVE_CAP_REACHED, LIVE_PROVIDER_DOWN, LIVE_RECORDING_NOT_READY.\n\n**Who can call:** partnerKey. API keys need scope `partner:links`.\n\n**Parameters**\n\n| Parameter | In | Type | Rules |\n|---|---|---|---|\n| `external_user_id` | query | string | Required; 3 to 200 characters. |\n\n**Response 200:** `{ data, meta }` where `data` is one PartnerLiveSessions.\n\n| Field | Type | Notes |\n|---|---|---|\n| `student_ref` | string | Always present; UUID. |\n| `sessions` | array of LiveSession | Always present. |\n\n**Errors**\n\n- 400 validation (UNKNOWN_FIELD, MISSING_FIELD, INVALID_TYPE, TEXT_TOO_LONG, INVALID_ENUM, OUT_OF_RANGE and others; see Validation rules)\n- 401 UNAUTHENTICATED or TOKEN_EXPIRED\n- 403 NOT_ALLOWED (role, scope, school or read-only View-as)\n- 429 RATE_LIMITED (see Retry-After)",
    "parameters": [
     {
      "$ref": "#/components/parameters/request_id"
     },
     {
      "name": "external_user_id",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string",
       "minLength": 3,
       "maxLength": 200
      }
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "$ref": "#/components/schemas/PartnerLiveSessions"
          }
         },
         "required": [
          "data"
         ]
        },
        "example": {
         "data": {
          "student_ref": "2f1c6a0e-8d7b-4c1e-9a55-3b1f0c2d4e6f",
          "sessions": [
           {
            "id": "2f1c6a0e-8d7b-4c1e-9a55-3b1f0c2d4e6f",
            "kind": "sabaq",
            "status": "scheduled",
            "starts_at": "2026-09-22T09:30:00Z",
            "minutes": 1,
            "ends_by": "2026-09-22T09:30:00Z",
            "mode": "audio",
            "recorded": true,
            "teacher": {
             "name": "string"
            },
            "range": {
             "surah": 1,
             "ayah_from": 1,
             "ayah_to": 1
            },
            "can_join": true,
            "join_blocked": "LIVE_NO_CONSENT",
            "result": {
             "sabaq": "pass",
             "sabqi": "pass",
             "manzil": "pass"
            }
           }
          ]
         },
         "meta": {
          "request_id": "req_01J8Z3X4",
          "generated_at": "2026-09-22T09:30:00Z"
         }
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "429": {
      "$ref": "#/components/responses/TooManyRequests"
     }
    },
    "x-scopes": [
     "partner:links"
    ],
    "x-partner-only": true,
    "security": [
     {
      "partnerKey": []
     }
    ]
   }
  },
  "/partner/live/sessions/{session_id}/join": {
   "post": {
    "tags": [
     "Partner"
    ],
    "summary": "Join a live session",
    "description": "A join pass for the linked student (role student: microphone only, never data). The answer carries the marks made so far and the page, for a late or reconnecting student. The pass lasts 10 minutes; refresh it with the token route. Errors: NOT_LINKED, LINK_PENDING, LIVE_ADDON_OFF, LIVE_DISABLED, LIVE_NOT_ON_ROSTER, LIVE_NOT_STARTED, LIVE_ENDED, LIVE_CANCELLED, LIVE_NO_CONSENT, LIVE_CAP_REACHED, LIVE_PROVIDER_DOWN, LIVE_RECORDING_NOT_READY.\n\n**Who can call:** partnerKey. API keys need scope `partner:links`.\n\n**Parameters**\n\n| Parameter | In | Type | Rules |\n|---|---|---|---|\n| `session_id` | path | string | Required; UUID; at most 40 characters. |\n\n**Request body** (JSON; unknown fields are rejected)\n\n| Field | Type | Rules |\n|---|---|---|\n| `external_user_id` | string | Required; 3 to 200 characters. |\n| `device` | object | Optional; What the person joins from, for the session record. |\n\n**Response 200:** `{ data, meta }` where `data` is one LiveJoin.\n\n| Field | Type | Notes |\n|---|---|---|\n| `url` | string | Always present; The audio service address the app connects to. Never shown to anyone. |\n| `token` | string | Always present; The join pass, valid 10 minutes; refresh it with the token route. |\n| `expires_at` | string | Always present; timestamp with offset or Z (RFC 3339). |\n| `role` | string | Always present; one of `teacher`, `student`, `listener`. |\n| `mode` | string | Always present; one of `audio`. |\n| `recording` | boolean | Always present. |\n| `ends_by` | string | Always present; timestamp with offset or Z (RFC 3339). |\n| `page` | object | Always present. |\n| `marks` | array of LiveMark | Always present. |\n| `identity` | string | May be omitted; The caller's id in the room. |\n| `name` | string | May be omitted; The name shown to everyone in the room. |\n\n**Errors**\n\n- 400 validation (UNKNOWN_FIELD, MISSING_FIELD, INVALID_TYPE, TEXT_TOO_LONG, INVALID_ENUM, OUT_OF_RANGE and others; see Validation rules)\n- 401 UNAUTHENTICATED or TOKEN_EXPIRED\n- 403 NOT_ALLOWED (role, scope, school or read-only View-as)\n- 404 NOT_FOUND (missing, or not visible to this caller)\n- 409 rule conflicts (for example SECTION_FULL, ON_HOLD, RECEIPT_IMMUTABLE)\n- 429 RATE_LIMITED (see Retry-After)",
    "parameters": [
     {
      "$ref": "#/components/parameters/request_id"
     },
     {
      "$ref": "#/components/parameters/idempotency"
     },
     {
      "name": "session_id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "maxLength": 40
      },
      "description": "The live session."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "external_user_id": {
          "type": "string",
          "minLength": 3,
          "maxLength": 200
         },
         "device": {
          "type": "object",
          "properties": {
           "platform": {
            "type": "string",
            "maxLength": 20
           },
           "app_version": {
            "type": "string",
            "maxLength": 20
           }
          },
          "description": "What the person joins from, for the session record.",
          "additionalProperties": false
         }
        },
        "required": [
         "external_user_id"
        ],
        "additionalProperties": false
       },
       "example": {
        "external_user_id": "2f1c6a0e-8d7b-4c1e-9a55-3b1f0c2d4e6f",
        "device": {
         "platform": "string",
         "app_version": "string"
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "$ref": "#/components/schemas/LiveJoin"
          }
         },
         "required": [
          "data"
         ]
        },
        "example": {
         "data": {
          "url": "string",
          "token": "string",
          "expires_at": "2026-09-22T09:30:00Z",
          "role": "teacher",
          "mode": "audio",
          "recording": true,
          "ends_by": "2026-09-22T09:30:00Z",
          "page": {
           "surah": 1,
           "ayah": 1
          },
          "marks": [
           {
            "id": "2f1c6a0e-8d7b-4c1e-9a55-3b1f0c2d4e6f",
            "surah": 1,
            "ayah": 1,
            "word": 1,
            "kind": "tajweed",
            "rule": "ghunnah",
            "note": "string",
            "at": "2026-09-22T09:30:00Z",
            "removed": true
           }
          ],
          "identity": "string",
          "name": "string"
         },
         "meta": {
          "request_id": "req_01J8Z3X4",
          "generated_at": "2026-09-22T09:30:00Z"
         }
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "429": {
      "$ref": "#/components/responses/TooManyRequests"
     }
    },
    "x-scopes": [
     "partner:links"
    ],
    "x-partner-only": true,
    "security": [
     {
      "partnerKey": []
     }
    ]
   }
  },
  "/partner/live/sessions/{session_id}/token": {
   "post": {
    "tags": [
     "Partner"
    ],
    "summary": "Refresh the join pass",
    "description": "A fresh 10-minute pass; call it before the old one expires. Errors: NOT_LINKED, LINK_PENDING, LIVE_ADDON_OFF, LIVE_DISABLED, LIVE_NOT_ON_ROSTER, LIVE_NOT_STARTED, LIVE_ENDED, LIVE_CANCELLED, LIVE_NO_CONSENT, LIVE_CAP_REACHED, LIVE_PROVIDER_DOWN, LIVE_RECORDING_NOT_READY.\n\n**Who can call:** partnerKey. API keys need scope `partner:links`.\n\n**Parameters**\n\n| Parameter | In | Type | Rules |\n|---|---|---|---|\n| `session_id` | path | string | Required; UUID; at most 40 characters. |\n\n**Request body** (JSON; unknown fields are rejected)\n\n| Field | Type | Rules |\n|---|---|---|\n| `external_user_id` | string | Required; 3 to 200 characters. |\n\n**Response 200:** `{ data, meta }` where `data` is one LiveToken.\n\n| Field | Type | Notes |\n|---|---|---|\n| `token` | string | Always present. |\n| `expires_at` | string | Always present; timestamp with offset or Z (RFC 3339). |\n\n**Errors**\n\n- 400 validation (UNKNOWN_FIELD, MISSING_FIELD, INVALID_TYPE, TEXT_TOO_LONG, INVALID_ENUM, OUT_OF_RANGE and others; see Validation rules)\n- 401 UNAUTHENTICATED or TOKEN_EXPIRED\n- 403 NOT_ALLOWED (role, scope, school or read-only View-as)\n- 404 NOT_FOUND (missing, or not visible to this caller)\n- 409 rule conflicts (for example SECTION_FULL, ON_HOLD, RECEIPT_IMMUTABLE)\n- 429 RATE_LIMITED (see Retry-After)",
    "parameters": [
     {
      "$ref": "#/components/parameters/request_id"
     },
     {
      "$ref": "#/components/parameters/idempotency"
     },
     {
      "name": "session_id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "maxLength": 40
      },
      "description": "The live session."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "external_user_id": {
          "type": "string",
          "minLength": 3,
          "maxLength": 200
         }
        },
        "required": [
         "external_user_id"
        ],
        "additionalProperties": false
       },
       "example": {
        "external_user_id": "2f1c6a0e-8d7b-4c1e-9a55-3b1f0c2d4e6f"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "$ref": "#/components/schemas/LiveToken"
          }
         },
         "required": [
          "data"
         ]
        },
        "example": {
         "data": {
          "token": "string",
          "expires_at": "2026-09-22T09:30:00Z"
         },
         "meta": {
          "request_id": "req_01J8Z3X4",
          "generated_at": "2026-09-22T09:30:00Z"
         }
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "429": {
      "$ref": "#/components/responses/TooManyRequests"
     }
    },
    "x-scopes": [
     "partner:links"
    ],
    "x-partner-only": true,
    "security": [
     {
      "partnerKey": []
     }
    ]
   }
  },
  "/partner/live/sessions/{session_id}/review": {
   "get": {
    "tags": [
     "Partner"
    ],
    "summary": "Session review",
    "description": "The session, the student's time in the room, the marks, the result, the next assignment and whether the recording is ready. Errors: NOT_LINKED, LINK_PENDING, LIVE_ADDON_OFF, LIVE_DISABLED, LIVE_NOT_ON_ROSTER, LIVE_NOT_STARTED, LIVE_ENDED, LIVE_CANCELLED, LIVE_NO_CONSENT, LIVE_CAP_REACHED, LIVE_PROVIDER_DOWN, LIVE_RECORDING_NOT_READY.\n\n**Who can call:** partnerKey. API keys need scope `partner:links`.\n\n**Parameters**\n\n| Parameter | In | Type | Rules |\n|---|---|---|---|\n| `session_id` | path | string | Required; UUID; at most 40 characters. |\n| `external_user_id` | query | string | Required; 3 to 200 characters. |\n\n**Response 200:** `{ data, meta }` where `data` is one LiveReview.\n\n| Field | Type | Notes |\n|---|---|---|\n| `session` | LiveSession | Always present. |\n| `attendance` | object | Always present. |\n| `marks` | array of LiveMark | Always present. |\n| `result` | LiveResultParts | Always present. |\n| `next_assignment` | string | Always present; may be null. |\n| `note` | string | Always present; may be null. |\n| `recording` | object | Always present. |\n\n**Errors**\n\n- 400 validation (UNKNOWN_FIELD, MISSING_FIELD, INVALID_TYPE, TEXT_TOO_LONG, INVALID_ENUM, OUT_OF_RANGE and others; see Validation rules)\n- 401 UNAUTHENTICATED or TOKEN_EXPIRED\n- 403 NOT_ALLOWED (role, scope, school or read-only View-as)\n- 404 NOT_FOUND (missing, or not visible to this caller)\n- 429 RATE_LIMITED (see Retry-After)",
    "parameters": [
     {
      "$ref": "#/components/parameters/request_id"
     },
     {
      "name": "session_id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "maxLength": 40
      },
      "description": "The live session."
     },
     {
      "name": "external_user_id",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string",
       "minLength": 3,
       "maxLength": 200
      }
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "$ref": "#/components/schemas/LiveReview"
          }
         },
         "required": [
          "data"
         ]
        },
        "example": {
         "data": {
          "session": {
           "id": "2f1c6a0e-8d7b-4c1e-9a55-3b1f0c2d4e6f",
           "kind": "sabaq",
           "status": "scheduled",
           "starts_at": "2026-09-22T09:30:00Z",
           "minutes": 1,
           "ends_by": "2026-09-22T09:30:00Z",
           "mode": "audio",
           "recorded": true,
           "teacher": {
            "name": "string"
           },
           "range": {
            "surah": 1,
            "ayah_from": 1,
            "ayah_to": 1
           },
           "can_join": true,
           "join_blocked": "LIVE_NO_CONSENT",
           "result": {
            "sabaq": "pass",
            "sabqi": "pass",
            "manzil": "pass"
           }
          },
          "attendance": {
           "joined_at": "2026-09-22T09:30:00Z",
           "left_at": "2026-09-22T09:30:00Z",
           "seconds": 1
          },
          "marks": [
           {
            "id": "2f1c6a0e-8d7b-4c1e-9a55-3b1f0c2d4e6f",
            "surah": 1,
            "ayah": 1,
            "word": 1,
            "kind": "tajweed",
            "rule": "ghunnah",
            "note": "string",
            "at": "2026-09-22T09:30:00Z",
            "removed": true
           }
          ],
          "result": {
           "sabaq": "pass",
           "sabqi": "pass",
           "manzil": "pass"
          },
          "next_assignment": "string",
          "note": "string",
          "recording": {
           "available": true,
           "started_at": "2026-09-22T09:30:00Z",
           "duration_seconds": 1
          }
         },
         "meta": {
          "request_id": "req_01J8Z3X4",
          "generated_at": "2026-09-22T09:30:00Z"
         }
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "429": {
      "$ref": "#/components/responses/TooManyRequests"
     }
    },
    "x-scopes": [
     "partner:links"
    ],
    "x-partner-only": true,
    "security": [
     {
      "partnerKey": []
     }
    ]
   }
  },
  "/partner/live/sessions/{session_id}/play": {
   "get": {
    "tags": [
     "Partner"
    ],
    "summary": "Play the recording",
    "description": "A 10-minute link on the API host that streams the recording; each play is logged. Never downloadable. Errors: NOT_LINKED, LINK_PENDING, LIVE_ADDON_OFF, LIVE_DISABLED, LIVE_NOT_ON_ROSTER, LIVE_NOT_STARTED, LIVE_ENDED, LIVE_CANCELLED, LIVE_NO_CONSENT, LIVE_CAP_REACHED, LIVE_PROVIDER_DOWN, LIVE_RECORDING_NOT_READY.\n\n**Who can call:** partnerKey. API keys need scope `partner:links`.\n\n**Parameters**\n\n| Parameter | In | Type | Rules |\n|---|---|---|---|\n| `session_id` | path | string | Required; UUID; at most 40 characters. |\n| `external_user_id` | query | string | Required; 3 to 200 characters. |\n\n**Response 200:** `{ data, meta }` where `data` is one LivePlayLink.\n\n| Field | Type | Notes |\n|---|---|---|\n| `url` | string | Always present; A 10-minute link on the API host that streams the recording. Each play is logged; recordings are never downloadable. |\n| `expires_at` | string | Always present; timestamp with offset or Z (RFC 3339). |\n| `content_type` | string | Always present; at most 40 characters. |\n| `duration_seconds` | integer | Always present. |\n\n**Errors**\n\n- 400 validation (UNKNOWN_FIELD, MISSING_FIELD, INVALID_TYPE, TEXT_TOO_LONG, INVALID_ENUM, OUT_OF_RANGE and others; see Validation rules)\n- 401 UNAUTHENTICATED or TOKEN_EXPIRED\n- 403 NOT_ALLOWED (role, scope, school or read-only View-as)\n- 404 NOT_FOUND (missing, or not visible to this caller)\n- 429 RATE_LIMITED (see Retry-After)",
    "parameters": [
     {
      "$ref": "#/components/parameters/request_id"
     },
     {
      "name": "session_id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "maxLength": 40
      },
      "description": "The live session."
     },
     {
      "name": "external_user_id",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string",
       "minLength": 3,
       "maxLength": 200
      }
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "$ref": "#/components/schemas/LivePlayLink"
          }
         },
         "required": [
          "data"
         ]
        },
        "example": {
         "data": {
          "url": "string",
          "expires_at": "2026-09-22T09:30:00Z",
          "content_type": "string",
          "duration_seconds": 1
         },
         "meta": {
          "request_id": "req_01J8Z3X4",
          "generated_at": "2026-09-22T09:30:00Z"
         }
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "429": {
      "$ref": "#/components/responses/TooManyRequests"
     }
    },
    "x-scopes": [
     "partner:links"
    ],
    "x-partner-only": true,
    "security": [
     {
      "partnerKey": []
     }
    ]
   }
  },
  "/partner/live/sessions/{session_id}/report": {
   "post": {
    "tags": [
     "Partner"
    ],
    "summary": "Report a problem",
    "description": "From the student in the app: sound, unsafe or other, with an optional note. The saMas safety team and the principal answer within 24 hours; the recording is held until then. Errors: NOT_LINKED, LINK_PENDING, LIVE_ADDON_OFF, LIVE_DISABLED, LIVE_NOT_ON_ROSTER, LIVE_NOT_STARTED, LIVE_ENDED, LIVE_CANCELLED, LIVE_NO_CONSENT, LIVE_CAP_REACHED, LIVE_PROVIDER_DOWN, LIVE_RECORDING_NOT_READY.\n\n**Who can call:** partnerKey. API keys need scope `partner:links`.\n\n**Parameters**\n\n| Parameter | In | Type | Rules |\n|---|---|---|---|\n| `session_id` | path | string | Required; UUID; at most 40 characters. |\n\n**Request body** (JSON; unknown fields are rejected)\n\n| Field | Type | Rules |\n|---|---|---|\n| `external_user_id` | string | Required; 3 to 200 characters. |\n| `kind` | string | Required; one of `sound`, `unsafe`, `other`. |\n| `note` | string | Optional; at most 500 characters. |\n\n**Response 201:** `{ data, meta }` where `data` is one LiveReportOpened.\n\n| Field | Type | Notes |\n|---|---|---|\n| `report_id` | string | Always present; UUID. |\n| `status` | string | Always present; one of `open`. |\n\n**Errors**\n\n- 400 validation (UNKNOWN_FIELD, MISSING_FIELD, INVALID_TYPE, TEXT_TOO_LONG, INVALID_ENUM, OUT_OF_RANGE and others; see Validation rules)\n- 401 UNAUTHENTICATED or TOKEN_EXPIRED\n- 403 NOT_ALLOWED (role, scope, school or read-only View-as)\n- 404 NOT_FOUND (missing, or not visible to this caller)\n- 409 rule conflicts (for example SECTION_FULL, ON_HOLD, RECEIPT_IMMUTABLE)\n- 429 RATE_LIMITED (see Retry-After)",
    "parameters": [
     {
      "$ref": "#/components/parameters/request_id"
     },
     {
      "$ref": "#/components/parameters/idempotency"
     },
     {
      "name": "session_id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "maxLength": 40
      },
      "description": "The live session."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "external_user_id": {
          "type": "string",
          "minLength": 3,
          "maxLength": 200
         },
         "kind": {
          "type": "string",
          "enum": [
           "sound",
           "unsafe",
           "other"
          ]
         },
         "note": {
          "type": "string",
          "maxLength": 500
         }
        },
        "required": [
         "external_user_id",
         "kind"
        ],
        "additionalProperties": false
       },
       "example": {
        "external_user_id": "2f1c6a0e-8d7b-4c1e-9a55-3b1f0c2d4e6f",
        "kind": "sound",
        "note": "string"
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Created.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "$ref": "#/components/schemas/LiveReportOpened"
          }
         },
         "required": [
          "data"
         ]
        },
        "example": {
         "data": {
          "report_id": "2f1c6a0e-8d7b-4c1e-9a55-3b1f0c2d4e6f",
          "status": "open"
         },
         "meta": {
          "request_id": "req_01J8Z3X4",
          "generated_at": "2026-09-22T09:30:00Z"
         }
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "429": {
      "$ref": "#/components/responses/TooManyRequests"
     }
    },
    "x-scopes": [
     "partner:links"
    ],
    "x-partner-only": true,
    "security": [
     {
      "partnerKey": []
     }
    ]
   }
  }
 },
 "components": {
  "securitySchemes": {
   "clerkToken": {
    "type": "http",
    "scheme": "bearer",
    "bearerFormat": "JWT",
    "description": "Session token of a signed-in person (the same token the web app uses). Role and school come from the person's active context."
   },
   "schoolKey": {
    "type": "apiKey",
    "in": "header",
    "name": "X-Api-Key",
    "description": "Per-school key (sk_school_...). Scoped; created by the school admin under Settings, API keys, or by the platform."
   },
   "platformKey": {
    "type": "apiKey",
    "in": "header",
    "name": "X-Api-Key",
    "description": "Platform key (sk_platform_...). Issued only to saMas School operators, never to schools."
   },
   "partnerKey": {
    "type": "apiKey",
    "in": "header",
    "name": "X-Api-Key",
    "description": "Partner key (sk_partner_...), one per school that connected the app, made by the school admin under Settings, Madrasa, Quran reading apps. Works on /v1/partner only."
   }
  },
  "parameters": {
   "cursor": {
    "name": "cursor",
    "in": "query",
    "schema": {
     "type": "string",
     "maxLength": 200
    },
    "description": "Cursor from the previous page."
   },
   "size": {
    "name": "size",
    "in": "query",
    "schema": {
     "type": "integer",
     "minimum": 1,
     "maximum": 200,
     "default": 50
    },
    "description": "Page size."
   },
   "id": {
    "name": "id",
    "in": "path",
    "required": true,
    "schema": {
     "type": "string",
     "format": "uuid",
     "maxLength": 40
    }
   },
   "student_id": {
    "name": "student_id",
    "in": "path",
    "required": true,
    "schema": {
     "type": "string",
     "format": "uuid",
     "maxLength": 40
    }
   },
   "section_id": {
    "name": "section_id",
    "in": "path",
    "required": true,
    "schema": {
     "type": "string",
     "format": "uuid",
     "maxLength": 40
    }
   },
   "shift_id": {
    "name": "shift_id",
    "in": "path",
    "required": true,
    "schema": {
     "type": "string",
     "format": "uuid",
     "maxLength": 40
    }
   },
   "version_id": {
    "name": "version_id",
    "in": "path",
    "required": true,
    "schema": {
     "type": "string",
     "format": "uuid",
     "maxLength": 40
    }
   },
   "timing_id": {
    "name": "timing_id",
    "in": "path",
    "required": true,
    "schema": {
     "type": "string",
     "format": "uuid",
     "maxLength": 40
    }
   },
   "room_id": {
    "name": "room_id",
    "in": "path",
    "required": true,
    "schema": {
     "type": "string",
     "format": "uuid",
     "maxLength": 40
    }
   },
   "teacher_id": {
    "name": "teacher_id",
    "in": "path",
    "required": true,
    "schema": {
     "type": "string",
     "format": "uuid",
     "maxLength": 40
    }
   },
   "idempotency": {
    "name": "Idempotency-Key",
    "in": "header",
    "schema": {
     "type": "string",
     "maxLength": 64
    },
    "description": "Send a unique value per intended write; a retry with the same key returns the original result instead of a duplicate."
   },
   "school_header": {
    "name": "X-School-Id",
    "in": "header",
    "schema": {
     "type": "string",
     "format": "uuid",
     "maxLength": 40
    },
    "description": "Platform keys only, and required for them on the Admin API: the school the key works inside for this request (L81). A signed-in person's school comes from their sign-in and a school key's from the key; both ignore it."
   },
   "request_id": {
    "name": "X-Request-Id",
    "in": "header",
    "schema": {
     "type": "string",
     "maxLength": 64
    },
    "description": "Echoed back in the response for tracing."
   },
   "recitation_id": {
    "name": "recitation_id",
    "in": "path",
    "required": true,
    "schema": {
     "type": "string",
     "format": "uuid",
     "maxLength": 40
    }
   }
  },
  "responses": {
   "BadRequest": {
    "description": "Validation failed.",
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      },
      "example": {
       "error": {
        "code": "MISSING_FIELD",
        "message": "A required field is missing.",
        "hint": "'full_name' is required.",
        "field": "/body/full_name",
        "request_id": "req_01J8Z3X4"
       }
      }
     }
    }
   },
   "Unauthorized": {
    "description": "Missing or invalid credentials.",
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      },
      "example": {
       "error": {
        "code": "MISSING_FIELD",
        "message": "A required field is missing.",
        "hint": "'full_name' is required.",
        "field": "/body/full_name",
        "request_id": "req_01J8Z3X4"
       }
      }
     }
    }
   },
   "Forbidden": {
    "description": "Authenticated, but not allowed (role, scope, school, read-only View-as).",
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      },
      "example": {
       "error": {
        "code": "MISSING_FIELD",
        "message": "A required field is missing.",
        "hint": "'full_name' is required.",
        "field": "/body/full_name",
        "request_id": "req_01J8Z3X4"
       }
      }
     }
    }
   },
   "NotFound": {
    "description": "Not found, or not visible to this caller (the two are not distinguished).",
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      },
      "example": {
       "error": {
        "code": "MISSING_FIELD",
        "message": "A required field is missing.",
        "hint": "'full_name' is required.",
        "field": "/body/full_name",
        "request_id": "req_01J8Z3X4"
       }
      }
     }
    }
   },
   "Conflict": {
    "description": "Rule violated (SECTION_FULL, HAS_PAYMENTS, ON_HOLD, ALREADY_DECIDED, RECEIPT_IMMUTABLE...).",
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      },
      "example": {
       "error": {
        "code": "MISSING_FIELD",
        "message": "A required field is missing.",
        "hint": "'full_name' is required.",
        "field": "/body/full_name",
        "request_id": "req_01J8Z3X4"
       }
      }
     }
    }
   },
   "TooManyRequests": {
    "description": "Rate limit exceeded. Retry-After says when.",
    "headers": {
     "Retry-After": {
      "schema": {
       "type": "integer"
      }
     }
    },
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      },
      "example": {
       "error": {
        "code": "MISSING_FIELD",
        "message": "A required field is missing.",
        "hint": "'full_name' is required.",
        "field": "/body/full_name",
        "request_id": "req_01J8Z3X4"
       }
      }
     }
    }
   }
  },
  "schemas": {
   "Error": {
    "type": "object",
    "properties": {
     "error": {
      "type": "object",
      "properties": {
       "code": {
        "type": "string",
        "description": "Stable machine code, the same one the database raises (NOT_ALLOWED, SECTION_FULL, RECEIPT_IMMUTABLE, ON_HOLD...).",
        "example": "SECTION_FULL"
       },
       "message": {
        "type": "string",
        "description": "Human sentence for the person, safe to show.",
        "example": "This section is full (30 of 30 seats). Raise the capacity or pick another section."
       },
       "hint": {
        "type": "string",
        "description": "Optional extra guidance."
       },
       "details": {
        "type": "object",
        "additionalProperties": true,
        "description": "Facts beside the hint when the server has them, for a screen to offer the fix: the next free number (ADMISSION_NO_TAKEN, ROLL_NO_TAKEN), who holds a phone, masked (GUARDIAN_PHONE_IN_USE), the next school day (DAY_CLOSED)."
       },
       "request_id": {
        "type": "string"
       }
      },
      "required": [
       "code",
       "message"
      ]
     }
    },
    "required": [
     "error"
    ]
   },
   "PersonRef": {
    "type": "object",
    "properties": {
     "user_id": {
      "type": "string",
      "format": "uuid"
     },
     "full_name": {
      "type": [
       "string",
       "null"
      ]
     }
    },
    "required": [
     "user_id",
     "full_name"
    ]
   },
   "LiveResultParts": {
    "type": "object",
    "properties": {
     "sabaq": {
      "type": "string",
      "enum": [
       "pass",
       "repeat",
       "needs_work"
      ]
     },
     "sabqi": {
      "type": [
       "string",
       "null"
      ],
      "enum": [
       "pass",
       "repeat",
       "needs_work",
       null
      ]
     },
     "manzil": {
      "type": [
       "string",
       "null"
      ],
      "enum": [
       "pass",
       "repeat",
       "needs_work",
       null
      ]
     }
    }
   },
   "LiveSession": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "format": "uuid"
     },
     "kind": {
      "type": "string",
      "enum": [
       "sabaq"
      ]
     },
     "status": {
      "type": "string",
      "enum": [
       "scheduled",
       "live",
       "ended",
       "missed",
       "cancelled"
      ]
     },
     "starts_at": {
      "type": "string",
      "format": "date-time"
     },
     "minutes": {
      "type": "integer"
     },
     "ends_by": {
      "type": "string",
      "description": "Started: when the time is up. Scheduled: the planned end.",
      "format": "date-time"
     },
     "mode": {
      "type": "string",
      "enum": [
       "audio"
      ]
     },
     "recorded": {
      "type": "boolean",
      "description": "Always true: every one-to-one session is recorded."
     },
     "teacher": {
      "type": "object",
      "properties": {
       "name": {
        "type": "string",
        "maxLength": 120
       }
      },
      "required": [
       "name"
      ]
     },
     "range": {
      "oneOf": [
       {
        "type": "object",
        "properties": {
         "surah": {
          "type": "integer"
         },
         "ayah_from": {
          "type": "integer"
         },
         "ayah_to": {
          "type": "integer"
         }
        },
        "required": [
         "surah",
         "ayah_from",
         "ayah_to"
        ]
       },
       {
        "type": "null"
       }
      ]
     },
     "can_join": {
      "type": "boolean"
     },
     "join_blocked": {
      "type": [
       "string",
       "null"
      ],
      "enum": [
       "LIVE_NO_CONSENT",
       "LIVE_NOT_STARTED",
       "LIVE_ENDED",
       "LIVE_DISABLED",
       "LIVE_CAP_REACHED",
       null
      ]
     },
     "result": {
      "oneOf": [
       {
        "$ref": "#/components/schemas/LiveResultParts"
       },
       {
        "type": "null"
       }
      ]
     }
    },
    "required": [
     "id",
     "kind",
     "status",
     "starts_at",
     "minutes",
     "ends_by",
     "mode",
     "recorded",
     "teacher",
     "range",
     "can_join",
     "join_blocked",
     "result"
    ]
   },
   "LiveMark": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "format": "uuid"
     },
     "surah": {
      "type": "integer"
     },
     "ayah": {
      "type": "integer"
     },
     "word": {
      "type": "integer",
      "description": "0-based word index, the same as the Quran partner contract's word_index."
     },
     "kind": {
      "type": "string",
      "enum": [
       "tajweed",
       "wrong_word",
       "skipped",
       "added",
       "hesitation",
       "makhraj"
      ]
     },
     "rule": {
      "type": [
       "string",
       "null"
      ],
      "enum": [
       "ghunnah",
       "madd",
       "qalqalah",
       "ikhfa",
       "idgham",
       "iqlab",
       "izhar",
       "other",
       null
      ]
     },
     "note": {
      "type": [
       "string",
       "null"
      ]
     },
     "at": {
      "type": "string",
      "description": "Server time; replay works out the offset from the recording's start.",
      "format": "date-time"
     },
     "removed": {
      "type": "boolean"
     }
    },
    "required": [
     "id",
     "surah",
     "ayah",
     "word",
     "kind",
     "rule",
     "note",
     "at",
     "removed"
    ]
   },
   "LiveJoin": {
    "type": "object",
    "properties": {
     "url": {
      "type": "string",
      "description": "The audio service address the app connects to. Never shown to anyone."
     },
     "token": {
      "type": "string",
      "description": "The join pass, valid 10 minutes; refresh it with the token route."
     },
     "expires_at": {
      "type": "string",
      "format": "date-time"
     },
     "role": {
      "type": "string",
      "enum": [
       "teacher",
       "student",
       "listener"
      ]
     },
     "mode": {
      "type": "string",
      "enum": [
       "audio"
      ]
     },
     "recording": {
      "type": "boolean"
     },
     "ends_by": {
      "type": "string",
      "format": "date-time"
     },
     "page": {
      "oneOf": [
       {
        "type": "object",
        "properties": {
         "surah": {
          "type": "integer"
         },
         "ayah": {
          "type": "integer"
         }
        },
        "required": [
         "surah",
         "ayah"
        ]
       },
       {
        "type": "null"
       }
      ]
     },
     "marks": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/LiveMark"
      }
     },
     "identity": {
      "type": "string",
      "description": "The caller's id in the room."
     },
     "name": {
      "type": "string",
      "description": "The name shown to everyone in the room."
     }
    },
    "required": [
     "url",
     "token",
     "expires_at",
     "role",
     "mode",
     "recording",
     "ends_by",
     "page",
     "marks"
    ]
   },
   "LiveToken": {
    "type": "object",
    "properties": {
     "token": {
      "type": "string"
     },
     "expires_at": {
      "type": "string",
      "format": "date-time"
     }
    },
    "required": [
     "token",
     "expires_at"
    ]
   },
   "LiveReview": {
    "type": "object",
    "properties": {
     "session": {
      "$ref": "#/components/schemas/LiveSession"
     },
     "attendance": {
      "oneOf": [
       {
        "type": "object",
        "properties": {
         "joined_at": {
          "type": "string",
          "format": "date-time"
         },
         "left_at": {
          "type": [
           "string",
           "null"
          ],
          "format": "date-time"
         },
         "seconds": {
          "type": "integer"
         }
        },
        "required": [
         "joined_at",
         "seconds"
        ]
       },
       {
        "type": "null"
       }
      ],
      "description": "When the student was in the room (this session only)."
     },
     "marks": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/LiveMark"
      }
     },
     "result": {
      "oneOf": [
       {
        "$ref": "#/components/schemas/LiveResultParts"
       },
       {
        "type": "null"
       }
      ]
     },
     "next_assignment": {
      "type": [
       "string",
       "null"
      ]
     },
     "note": {
      "type": [
       "string",
       "null"
      ]
     },
     "recording": {
      "oneOf": [
       {
        "type": "object",
        "properties": {
         "available": {
          "const": true
         },
         "started_at": {
          "type": "string",
          "format": "date-time"
         },
         "duration_seconds": {
          "type": "integer"
         }
        },
        "required": [
         "available",
         "started_at",
         "duration_seconds"
        ]
       },
       {
        "type": "object",
        "properties": {
         "available": {
          "const": false
         }
        },
        "required": [
         "available"
        ]
       }
      ]
     }
    },
    "required": [
     "session",
     "attendance",
     "marks",
     "result",
     "next_assignment",
     "note",
     "recording"
    ]
   },
   "LivePlayLink": {
    "type": "object",
    "properties": {
     "url": {
      "type": "string",
      "description": "A 10-minute link on the API host that streams the recording. Each play is logged; recordings are never downloadable."
     },
     "expires_at": {
      "type": "string",
      "format": "date-time"
     },
     "content_type": {
      "type": "string",
      "maxLength": 40
     },
     "duration_seconds": {
      "type": "integer"
     }
    },
    "required": [
     "url",
     "expires_at",
     "content_type",
     "duration_seconds"
    ]
   },
   "LiveReportOpened": {
    "type": "object",
    "properties": {
     "report_id": {
      "type": "string",
      "format": "uuid"
     },
     "status": {
      "type": "string",
      "enum": [
       "open"
      ]
     }
    },
    "required": [
     "report_id",
     "status"
    ]
   },
   "PartnerMe": {
    "type": "object",
    "properties": {
     "partner": {
      "type": "object",
      "properties": {
       "id": {
        "type": "string",
        "format": "uuid"
       },
       "name": {
        "type": "string",
        "maxLength": 40
       },
       "slug": {
        "type": "string",
        "maxLength": 30
       },
       "capabilities": {
        "type": "array",
        "items": {
         "type": "string"
        }
       }
      },
      "required": [
       "id",
       "name",
       "slug",
       "capabilities"
      ]
     },
     "school": {
      "type": "object",
      "properties": {
       "name": {
        "type": "string",
        "maxLength": 120
       }
      },
      "required": [
       "name"
      ]
     },
     "scopes": {
      "type": "array",
      "items": {
       "type": "string"
      }
     },
     "links": {
      "type": "object",
      "properties": {
       "active": {
        "type": "integer"
       },
       "pending": {
        "type": "integer"
       }
      },
      "required": [
       "active",
       "pending"
      ]
     },
     "contract": {
      "type": "object",
      "properties": {
       "version": {
        "type": "string",
        "maxLength": 10
       },
       "docs": {
        "type": "string",
        "format": "uri"
       },
       "text": {
        "type": "string",
        "description": "The Quran text and counting both sides use.",
        "maxLength": 200
       },
       "word_index": {
        "type": "string",
        "maxLength": 200
       }
      },
      "required": [
       "version",
       "docs",
       "text",
       "word_index"
      ]
     }
    },
    "required": [
     "partner",
     "school",
     "scopes",
     "links",
     "contract"
    ]
   },
   "ClaimStudent": {
    "type": "object",
    "properties": {
     "pick_token": {
      "type": "string",
      "description": "One-time token for this name; valid with the claim for 15 minutes.",
      "maxLength": 64
     },
     "first_name": {
      "type": "string",
      "maxLength": 60
     },
     "family_initial": {
      "type": [
       "string",
       "null"
      ],
      "maxLength": 1
     }
    },
    "required": [
     "pick_token",
     "first_name"
    ]
   },
   "Claim": {
    "type": "object",
    "properties": {
     "claim_token": {
      "type": "string",
      "maxLength": 64
     },
     "expires_at": {
      "type": "string",
      "format": "date-time"
     },
     "school": {
      "type": "object",
      "properties": {
       "name": {
        "type": "string",
        "maxLength": 120
       }
      },
      "required": [
       "name"
      ]
     },
     "halaqa": {
      "type": "object",
      "properties": {
       "label": {
        "type": "string",
        "maxLength": 60
       }
      },
      "required": [
       "label"
      ]
     },
     "teacher": {
      "type": [
       "string",
       "null"
      ],
      "maxLength": 60
     },
     "students": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/ClaimStudent"
      }
     }
    },
    "required": [
     "claim_token",
     "expires_at",
     "school",
     "halaqa",
     "students"
    ]
   },
   "PartnerLink": {
    "type": "object",
    "properties": {
     "link_id": {
      "type": "string",
      "format": "uuid"
     },
     "student_ref": {
      "type": "string",
      "description": "Equal to link_id: the only id the app ever holds for a student.",
      "format": "uuid"
     },
     "status": {
      "type": "string",
      "enum": [
       "pending",
       "active",
       "revoked",
       "expired"
      ]
     },
     "first_name": {
      "type": "string",
      "maxLength": 60
     },
     "halaqa": {
      "type": [
       "string",
       "null"
      ],
      "maxLength": 60
     },
     "school": {
      "type": "string",
      "maxLength": 120
     },
     "teacher": {
      "type": [
       "string",
       "null"
      ],
      "maxLength": 60
     },
     "program": {
      "type": [
       "string",
       "null"
      ],
      "maxLength": 20
     },
     "requested_at": {
      "type": "string",
      "format": "date-time"
     },
     "expires_at": {
      "type": [
       "string",
       "null"
      ],
      "format": "date-time"
     },
     "linked_at": {
      "type": [
       "string",
       "null"
      ],
      "format": "date-time"
     },
     "revoked_at": {
      "type": [
       "string",
       "null"
      ],
      "format": "date-time"
     },
     "revoked_reason": {
      "type": [
       "string",
       "null"
      ],
      "description": "parent, school, partner, declined, expired or student."
     }
    },
    "required": [
     "link_id",
     "student_ref",
     "status",
     "first_name",
     "school",
     "requested_at"
    ]
   },
   "PracticeDay": {
    "type": "object",
    "properties": {
     "on_date": {
      "type": "string",
      "format": "date",
      "example": "2026-09-01",
      "maxLength": 40
     },
     "ayahs": {
      "type": "array",
      "items": {
       "type": "array",
       "items": {
        "type": "integer",
        "minimum": 1,
        "maximum": 286
       },
       "minItems": 2,
       "maxItems": 2
      },
      "maxItems": 6236,
      "description": "[surah, ayah] pairs the student read that day; duplicates are folded."
     },
     "minutes_estimated": {
      "type": "integer",
      "minimum": 0,
      "maximum": 600,
      "description": "Clustered reading time; the school labels it estimated."
     },
     "source_id": {
      "type": "string",
      "description": "The app's own id for the day, for idempotency.",
      "maxLength": 80
     }
    },
    "required": [
     "on_date",
     "ayahs"
    ],
    "additionalProperties": false
   },
   "PracticeAccepted": {
    "type": "object",
    "properties": {
     "accepted": {
      "type": "integer"
     },
     "replaced": {
      "type": "integer"
     },
     "student_ref": {
      "type": "string",
      "format": "uuid"
     }
    },
    "required": [
     "accepted",
     "replaced",
     "student_ref"
    ]
   },
   "PartnerLesson": {
    "type": "object",
    "properties": {
     "lesson_id": {
      "type": "string",
      "format": "uuid"
     },
     "on": {
      "type": "string",
      "format": "date",
      "example": "2026-09-01"
     },
     "part": {
      "type": "string",
      "enum": [
       "sabaq",
       "sabqi",
       "manzil"
      ]
     },
     "kind": {
      "type": "string",
      "enum": [
       "range",
       "juz",
       "qaida"
      ]
     },
     "surah": {
      "type": "integer"
     },
     "surah_name": {
      "type": "string",
      "maxLength": 40
     },
     "ayah_from": {
      "type": "integer"
     },
     "ayah_to": {
      "type": "integer"
     },
     "juz_from": {
      "type": "integer"
     },
     "juz_to": {
      "type": "integer"
     },
     "qaida_lesson": {
      "type": "integer"
     },
     "riwayah": {
      "type": "string",
      "maxLength": 20
     },
     "due_date": {
      "type": "string",
      "format": "date",
      "example": "2026-09-01"
     },
     "status": {
      "type": "string",
      "enum": [
       "assigned",
       "withdrawn",
       "submitted",
       "graded"
      ]
     },
     "result": {
      "type": "string",
      "enum": [
       "pending",
       "passed",
       "repeat",
       "absent"
      ]
     },
     "grade": {
      "type": "string",
      "enum": [
       "mumtaz",
       "jayyid_jiddan",
       "jayyid",
       "maqbul",
       "repeat"
      ]
     },
     "remark": {
      "type": "string",
      "maxLength": 200
     },
     "graded_at": {
      "type": "string",
      "format": "date-time"
     },
     "text": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "ayah": {
         "type": "integer"
        },
        "text": {
         "type": "string",
         "description": "The Uthmani ayah.",
         "maxLength": 2000
        }
       },
       "required": [
        "ayah",
        "text"
       ]
      }
     }
    },
    "required": [
     "lesson_id",
     "on",
     "part",
     "kind",
     "status"
    ],
    "description": "Fields that do not apply to the kind are left out; text is given for ranges under 50 ayahs."
   },
   "RecitationStart": {
    "type": "object",
    "properties": {
     "recitation_id": {
      "type": "string",
      "format": "uuid"
     },
     "student_ref": {
      "type": "string",
      "format": "uuid"
     },
     "attempt": {
      "type": "integer"
     },
     "upload": {
      "type": "object",
      "properties": {
       "kind": {
        "type": "string",
        "enum": [
         "single",
         "parts"
        ]
       },
       "part_bytes": {
        "type": "integer"
       },
       "parts": {
        "type": "array",
        "items": {
         "type": "object",
         "properties": {
          "part_number": {
           "type": "integer"
          },
          "url": {
           "type": "string",
           "format": "uri",
           "description": "PUT this part's bytes here with the Content-Type announced; valid 15 minutes."
          },
          "max_bytes": {
           "type": "integer"
          }
         },
         "required": [
          "part_number",
          "url",
          "max_bytes"
         ]
        }
       },
       "expires_at": {
        "type": "string",
        "format": "date-time"
       }
      },
      "required": [
       "kind",
       "part_bytes",
       "parts",
       "expires_at"
      ]
     }
    },
    "required": [
     "recitation_id",
     "student_ref",
     "attempt",
     "upload"
    ]
   },
   "PartnerRecitation": {
    "type": "object",
    "properties": {
     "recitation_id": {
      "type": "string",
      "format": "uuid"
     },
     "student_ref": {
      "type": "string",
      "format": "uuid"
     },
     "lesson_id": {
      "type": [
       "string",
       "null"
      ],
      "format": "uuid"
     },
     "kind": {
      "type": "string",
      "enum": [
       "student",
       "model",
       "juz_test"
      ]
     },
     "attempt": {
      "type": "integer"
     },
     "status": {
      "type": "string",
      "enum": [
       "uploading",
       "submitted",
       "reviewed",
       "deleted"
      ]
     },
     "surah": {
      "type": [
       "integer",
       "null"
      ]
     },
     "surah_name": {
      "type": [
       "string",
       "null"
      ]
     },
     "ayah_from": {
      "type": [
       "integer",
       "null"
      ]
     },
     "ayah_to": {
      "type": [
       "integer",
       "null"
      ]
     },
     "juz": {
      "type": [
       "integer",
       "null"
      ]
     },
     "duration_seconds": {
      "type": "integer"
     },
     "submitted_at": {
      "type": [
       "string",
       "null"
      ],
      "format": "date-time"
     },
     "reviewed_at": {
      "type": [
       "string",
       "null"
      ],
      "format": "date-time"
     },
     "teacher": {
      "type": [
       "string",
       "null"
      ],
      "maxLength": 60
     },
     "grade": {
      "type": [
       "string",
       "null"
      ]
     },
     "remark": {
      "type": [
       "string",
       "null"
      ]
     },
     "can_re_record": {
      "type": "boolean"
     },
     "notes": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "ayah": {
         "type": "integer"
        },
        "word_index": {
         "type": "integer"
        },
        "word": {
         "type": [
          "string",
          "null"
         ]
        },
        "category": {
         "type": "string",
         "maxLength": 20
        },
        "text": {
         "type": "string",
         "maxLength": 200
        },
        "at_seconds": {
         "type": [
          "integer",
          "null"
         ]
        }
       },
       "required": [
        "ayah",
        "word_index",
        "category",
        "text"
       ]
      }
     },
     "model": {
      "oneOf": [
       {
        "type": "object",
        "properties": {
         "recitation_id": {
          "type": "string",
          "format": "uuid"
         },
         "duration_seconds": {
          "type": "integer"
         },
         "available": {
          "type": "boolean"
         }
        },
        "required": [
         "recitation_id",
         "duration_seconds",
         "available"
        ]
       },
       {
        "type": "null"
       }
      ]
     }
    },
    "required": [
     "recitation_id",
     "student_ref",
     "kind",
     "attempt",
     "status",
     "duration_seconds",
     "can_re_record",
     "notes"
    ]
   },
   "PartnerPlayLink": {
    "type": "object",
    "properties": {
     "url": {
      "type": "string",
      "format": "uri"
     },
     "expires_at": {
      "type": "string",
      "format": "date-time"
     },
     "content_type": {
      "type": "string",
      "maxLength": 20
     },
     "duration_seconds": {
      "type": "integer"
     }
    },
    "required": [
     "url",
     "expires_at",
     "content_type",
     "duration_seconds"
    ]
   },
   "PartnerHomework": {
    "type": "object",
    "properties": {
     "student_ref": {
      "type": "string",
      "format": "uuid"
     },
     "first_name": {
      "type": "string",
      "maxLength": 60
     },
     "halaqa": {
      "type": [
       "string",
       "null"
      ],
      "maxLength": 60
     },
     "teacher": {
      "type": [
       "string",
       "null"
      ],
      "maxLength": 60
     },
     "program": {
      "type": [
       "string",
       "null"
      ],
      "maxLength": 20
     },
     "as_of": {
      "type": "string",
      "format": "date-time"
     },
     "lessons": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/PartnerLesson"
      }
     },
     "recent": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/PartnerLesson"
      }
     }
    },
    "required": [
     "student_ref",
     "first_name",
     "as_of",
     "lessons",
     "recent"
    ],
    "description": "lessons: open homework (assigned or submitted, due in the last 7 days or later), oldest first. recent: graded in the last 14 days."
   },
   "PartnerLiveSessions": {
    "type": "object",
    "properties": {
     "student_ref": {
      "type": "string",
      "format": "uuid"
     },
     "sessions": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/LiveSession"
      }
     }
    },
    "required": [
     "student_ref",
     "sessions"
    ]
   }
  }
 }
}