{
 "$schema": "https://json-schema.org/draft/2020-12/schema",
 "$id": "https://samas.school/api-docs/samas-app.schema.json",
 "title": "saMas School app manifest (Draft)",
 "$comment": "First-party apps are hosted on samas-apps.com (to be registered), never on a samas.school address, so saMas sign-in cookies are never in reach.",
 "description": "Published by a school app at /.well-known/samas-app.json. Draft, 29 October 2026; see the guide Build a school app (Draft).",
 "type": "object",
 "additionalProperties": false,
 "required": [
  "id",
  "name",
  "version",
  "publisher",
  "api_version",
  "scopes",
  "launch_url",
  "install_url",
  "uninstall_url",
  "privacy_url",
  "languages",
  "children_data",
  "delete_within_days"
 ],
 "properties": {
  "id": {
   "type": "string",
   "pattern": "^[a-z][a-z0-9-]{2,39}$",
   "description": "Unique, lower case, never changes."
  },
  "name": {
   "type": "string",
   "minLength": 2,
   "maxLength": 60
  },
  "version": {
   "type": "string",
   "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$"
  },
  "publisher": {
   "type": "object",
   "additionalProperties": false,
   "required": [
    "name",
    "email"
   ],
   "properties": {
    "name": {
     "type": "string",
     "maxLength": 80
    },
    "email": {
     "type": "string",
     "format": "email",
     "maxLength": 120
    },
    "url": {
     "type": "string",
     "format": "uri",
     "pattern": "^https://",
     "maxLength": 300
    }
   }
  },
  "api_version": {
   "const": "v1"
  },
  "summary": {
   "type": "string",
   "maxLength": 140,
   "description": "One line shown in Settings, Add-ons."
  },
  "scopes": {
   "type": "array",
   "minItems": 1,
   "maxItems": 20,
   "uniqueItems": true,
   "items": {
    "type": "object",
    "additionalProperties": false,
    "required": [
     "scope",
     "why"
    ],
    "properties": {
     "scope": {
      "type": "string",
      "enum": [
       "apps:me",
       "read:classes",
       "read:students",
       "read:schedule",
       "read:attendance",
       "write:attendance",
       "read:notes",
       "write:notes",
       "read:live",
       "read:recordings",
       "read:recitations"
      ]
     },
     "why": {
      "type": "string",
      "minLength": 5,
      "maxLength": 160
     }
    }
   }
  },
  "events": {
   "type": "array",
   "maxItems": 30,
   "uniqueItems": true,
   "items": {
    "type": "string",
    "pattern": "^(attendance\\.saved|student\\.enrolled|student\\.updated|lesson\\.assigned|lesson\\.graded|app\\.(installed|paused|resumed|uninstalled))$"
   }
  },
  "slots": {
   "type": "array",
   "maxItems": 5,
   "items": {
    "type": "object",
    "additionalProperties": false,
    "required": [
     "slot",
     "url",
     "roles"
    ],
    "properties": {
     "slot": {
      "type": "string",
      "enum": [
       "page",
       "home_card",
       "student_tab",
       "class_tab",
       "session_tab"
      ],
      "description": "Phase 2 opens page only."
     },
     "url": {
      "type": "string",
      "format": "uri",
      "pattern": "^https://",
      "maxLength": 300,
      "description": "Must be on the same origin as launch_url (checked at registration)."
     },
     "title": {
      "type": "string",
      "maxLength": 40
     },
     "roles": {
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "items": {
       "type": "string",
       "enum": [
        "teacher",
        "parent",
        "school_admin",
        "school_principal"
       ],
       "description": "Students come later, and only with an allowed guardian grant for that child."
      }
     }
    }
   }
  },
  "launch_url": {
   "type": "string",
   "format": "uri",
   "pattern": "^https://",
   "maxLength": 300
  },
  "install_url": {
   "type": "string",
   "format": "uri",
   "pattern": "^https://",
   "maxLength": 300
  },
  "uninstall_url": {
   "type": "string",
   "format": "uri",
   "pattern": "^https://",
   "maxLength": 300
  },
  "webhook_url": {
   "type": "string",
   "format": "uri",
   "pattern": "^https://",
   "maxLength": 300
  },
  "privacy_url": {
   "type": "string",
   "format": "uri",
   "pattern": "^https://",
   "maxLength": 300
  },
  "languages": {
   "type": "array",
   "minItems": 1,
   "uniqueItems": true,
   "items": {
    "type": "string",
    "enum": [
     "en",
     "ur"
    ]
   }
  },
  "children_data": {
   "type": "boolean",
   "description": "Derived from the scopes: true when any scope touches students, and then each guardian is asked. The schema refuses false with such a scope."
  },
  "delete_within_days": {
   "type": "integer",
   "minimum": 0,
   "maximum": 30
  }
 },
 "allOf": [
  {
   "if": {
    "properties": {
     "scopes": {
      "contains": {
       "properties": {
        "scope": {
         "enum": [
          "read:students",
          "read:attendance",
          "read:notes",
          "write:notes",
          "write:attendance",
          "read:live",
          "read:recordings",
          "read:recitations"
         ]
        }
       }
      }
     }
    },
    "required": [
     "scopes"
    ]
   },
   "then": {
    "properties": {
     "children_data": {
      "const": true
     }
    }
   }
  }
 ],
 "examples": [
  {
   "id": "mussarat-simple",
   "name": "Simple madrasa",
   "version": "1.0.0",
   "publisher": {
    "name": "saMas IT Services",
    "email": "apps@samas.school",
    "url": "https://samas.school"
   },
   "api_version": "v1",
   "summary": "Two big buttons for families and a one-screen day for the Qari or Qariyah.",
   "scopes": [
    {
     "scope": "apps:me",
     "why": "To greet the person and show the right page."
    },
    {
     "scope": "read:classes",
     "why": "To list today's classes."
    },
    {
     "scope": "read:students",
     "why": "To mark attendance and write notes."
    },
    {
     "scope": "write:attendance",
     "why": "The teacher marks the class from one screen."
    },
    {
     "scope": "write:notes",
     "why": "A short progress note for the family."
    },
    {
     "scope": "read:live",
     "why": "To show the next Live Sabaq and its Join button."
    },
    {
     "scope": "read:recordings",
     "why": "To list the child's Sabaq recordings to play."
    }
   ],
   "events": [
    "attendance.saved",
    "app.uninstalled"
   ],
   "slots": [
    {
     "slot": "page",
     "url": "https://simple.samas-apps.com/",
     "title": "Today",
     "roles": [
      "teacher",
      "parent"
     ]
    }
   ],
   "launch_url": "https://simple.samas-apps.com/",
   "install_url": "https://simple.samas-apps.com/hooks/install",
   "uninstall_url": "https://simple.samas-apps.com/hooks/uninstall",
   "webhook_url": "https://simple.samas-apps.com/hooks/events",
   "privacy_url": "https://samas.school/privacy",
   "languages": [
    "en",
    "ur"
   ],
   "children_data": true,
   "delete_within_days": 7
  }
 ]
}