{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://vibebase.me/contracts/principal/0.1.0",
  "title": "Principal",
  "type": "object",
  "additionalProperties": false,
  "$defs": {
    "kind": { "enum": ["admin", "builder", "app-user"] }
  },
  "required": ["subjectId", "kind", "tenant", "roles", "exp"],
  "properties": {
    "subjectId": { "type": "string", "minLength": 1 },
    "kind": { "$ref": "#/$defs/kind" },
    "tenant": { "type": "string", "minLength": 1 },
    "app": { "type": "string", "minLength": 1 },
    "roles": { "type": "array", "items": { "type": "string" } },
    "exp": { "type": "integer", "minimum": 0 }
  },
  "if": { "properties": { "kind": { "const": "app-user" } }, "required": ["kind"] },
  "then": { "properties": { "app": { "type": "string", "minLength": 1 } }, "required": ["app"] },
  "else": { "not": { "required": ["app"] } }
}
