{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://bpa.local/schemas/page-model/v1alpha1",
  "title": "BPA Page Model v1alpha1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "apiVersion",
    "kind",
    "metadata",
    "adapter",
    "origins",
    "states",
    "elements",
    "fixtureDigests"
  ],
  "properties": {
    "apiVersion": { "const": "bpa.page/v1alpha1" },
    "kind": { "const": "PageModel" },
    "metadata": { "$ref": "#/$defs/metadata" },
    "adapter": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "version", "digest"],
      "properties": {
        "id": { "$ref": "#/$defs/id" },
        "version": { "$ref": "#/$defs/semver" },
        "digest": { "$ref": "#/$defs/digest" }
      }
    },
    "origins": {
      "type": "array",
      "minItems": 1,
      "maxItems": 20,
      "uniqueItems": true,
      "items": { "type": "string", "format": "uri" }
    },
    "states": {
      "type": "array",
      "minItems": 1,
      "maxItems": 100,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["id", "pathPattern", "fingerprint"],
        "properties": {
          "id": { "$ref": "#/$defs/id" },
          "pathPattern": { "type": "string", "minLength": 1, "maxLength": 500 },
          "fingerprint": { "$ref": "#/$defs/digest" }
        }
      }
    },
    "elements": {
      "type": "array",
      "minItems": 1,
      "maxItems": 1000,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["id", "contract"],
        "properties": {
          "id": { "$ref": "#/$defs/id" },
          "contract": {
            "type": "object",
            "additionalProperties": false,
            "required": ["id", "version", "digest"],
            "properties": {
              "id": { "$ref": "#/$defs/id" },
              "version": { "$ref": "#/$defs/semver" },
              "digest": { "$ref": "#/$defs/digest" }
            }
          }
        }
      }
    },
    "fixtureDigests": {
      "type": "array",
      "minItems": 2,
      "maxItems": 100,
      "uniqueItems": true,
      "items": { "$ref": "#/$defs/digest" }
    }
  },
  "$defs": {
    "metadata": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "version", "title"],
      "properties": {
        "id": { "$ref": "#/$defs/id" },
        "version": { "$ref": "#/$defs/semver" },
        "title": { "type": "string", "minLength": 1, "maxLength": 200 },
        "description": { "type": "string", "maxLength": 4000 }
      }
    },
    "id": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9]*(?:[._-][a-z0-9]+)*$",
      "maxLength": 160
    },
    "semver": {
      "type": "string",
      "pattern": "^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(?:-[0-9A-Za-z.-]+)?$"
    },
    "digest": { "type": "string", "pattern": "^sha256:[a-f0-9]{64}$" }
  }
}
