{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://kabinethq.com/protocol/1/common.schema.json",
  "title": "Common",
  "description": "Pieces every area shares: keys, dates, error bodies.",
  "$defs": {
    "Key": {
      "title": "Key",
      "description": "A record key: an opaque string (an integer, a UUID…); only the backend knows what it means.",
      "type": "string",
      "minLength": 1
    },
    "Moment": {
      "title": "Moment",
      "description": "A moment: ISO 8601 in UTC with `Z`, any fraction of a second or none (`2026-12-03T10:15:30Z`).",
      "type": "string",
      "format": "date-time",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$"
    },
    "Day": {
      "title": "Day",
      "description": "A day without a time: `YYYY-MM-DD`, shown as is, never shifted by a time zone.",
      "type": "string",
      "format": "date",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
    },
    "Scalar": {
      "title": "Scalar",
      "description": "A record's value: records are flat, a relation's column comes as its own `relation.column` key.",
      "type": ["string", "number", "boolean", "null"]
    },
    "Choice": {
      "title": "Choice",
      "description": "A value with its label: a related record's key, an enum's value, a metric's range.",
      "type": "object",
      "required": ["value", "label"],
      "properties": {
        "value": { "type": "string" },
        "label": { "type": "string" }
      },
      "additionalProperties": false
    },
    "Option": {
      "title": "Option",
      "description": "A static option of a Select or a SelectFilter; with `depends`, shown only while each named field has one of the listed values.",
      "type": "object",
      "required": ["value", "label"],
      "properties": {
        "value": { "type": "string" },
        "label": { "type": "string" },
        "depends": {
          "type": "object",
          "minProperties": 1,
          "additionalProperties": { "type": "array", "minItems": 1, "items": { "type": "string" } }
        }
      },
      "additionalProperties": false
    },
    "Errors": {
      "title": "Errors",
      "description": "Validation errors by field (`filter.status` for a filter): one message per field, in the order of the form.",
      "type": "object",
      "minProperties": 1,
      "additionalProperties": {
        "type": "array",
        "minItems": 1,
        "maxItems": 1,
        "items": { "type": "string", "minLength": 1 }
      }
    },
    "Invalid": {
      "title": "Invalid",
      "description": "A 422: `message` is the first error (Laravel adds `(and N more errors)`).",
      "type": "object",
      "required": ["message", "errors"],
      "properties": {
        "message": { "type": "string", "minLength": 1 },
        "errors": { "$ref": "#/$defs/Errors" }
      },
      "additionalProperties": false
    },
    "Message": {
      "title": "Message",
      "description": "Any other error (401, 403, 404, 409, 419, 429): what went wrong, for a person; a policy's refusal carries its own text.",
      "type": "object",
      "required": ["message"],
      "properties": {
        "message": { "type": "string", "minLength": 1 }
      },
      "additionalProperties": false
    },
    "NoContent": {
      "title": "NoContent",
      "description": "A 204 has no body.",
      "type": "null"
    }
  }
}
