{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://schemas.kxm.dev/backup-manifest.schema.json",
  "title": "KXM SQLite stores backup manifest",
  "type": "object",
  "required": [
    "schema",
    "backupId",
    "createdAt",
    "stores"
  ],
  "properties": {
    "schema": {
      "const": "kxm.backup-manifest.v1"
    },
    "backupId": {
      "$ref": "common.schema.json#/$defs/opaqueId"
    },
    "createdAt": {
      "$ref": "common.schema.json#/$defs/timestamp"
    },
    "projectRoot": {
      "type": "string",
      "maxLength": 1024
    },
    "scope": {
      "description": "project: the checkout's stores and its own Runtime event store. all-projects: also the shared Runtime registry and every project's event store. Absent on manifests written before backups were scoped.",
      "enum": ["project", "all-projects"]
    },
    "stateRoot": {
      "description": "The user state root the Runtime stores were copied from.",
      "type": "string",
      "minLength": 1,
      "maxLength": 1024
    },
    "runtimeProjectKey": {
      "description": "The Runtime store key of the checkout the backup ran from.",
      "type": "string",
      "pattern": "^[0-9a-f]{24}$"
    },
    "stores": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/backupStoreRecord"
      },
      "minItems": 1,
      "maxItems": 64
    },
    "files": {
      "type": "array",
      "items": { "$ref": "#/$defs/backupFileRecord" },
      "maxItems": 64
    },
    "complete": { "type": "boolean" },
    "omitted": {
      "type": "array",
      "items": { "type": "string", "minLength": 1, "maxLength": 256 },
      "maxItems": 64
    },
    "manifestSha256": {
      "$ref": "common.schema.json#/$defs/sha256"
    }
  },
  "additionalProperties": false,
  "$defs": {
    "backupStoreRecord": {
      "type": "object",
      "required": [
        "storeId",
        "sourcePath",
        "backupFile",
        "schemaVersion",
        "sha256",
        "bytes",
        "integrity"
      ],
      "properties": {
        "storeId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 128,
          "pattern": "^[a-zA-Z0-9_.:-]+$"
        },
        "sourcePath": {
          "type": "string",
          "minLength": 1,
          "maxLength": 1024
        },
        "backupFile": {
          "type": "string",
          "minLength": 1,
          "maxLength": 256,
          "pattern": "^[a-zA-Z0-9_.-]+$"
        },
        "schemaVersion": {
          "type": "integer",
          "minimum": 0,
          "maximum": 1000000
        },
        "sha256": {
          "$ref": "common.schema.json#/$defs/sha256"
        },
        "bytes": {
          "type": "integer",
          "minimum": 0,
          "maximum": 107374182400
        },
        "integrity": {
          "const": "ok"
        }
      },
      "additionalProperties": false
    },
    "backupFileRecord": {
      "type": "object",
      "required": ["id", "sourcePath", "backupFile", "sha256", "bytes"],
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 128,
          "pattern": "^[a-zA-Z0-9_.:-]+$"
        },
        "sourcePath": { "type": "string", "minLength": 1, "maxLength": 1024 },
        "backupFile": {
          "type": "string",
          "minLength": 1,
          "maxLength": 256,
          "pattern": "^[a-zA-Z0-9_.-]+$"
        },
        "sha256": { "$ref": "common.schema.json#/$defs/sha256" },
        "bytes": { "type": "integer", "minimum": 0, "maximum": 107374182400 }
      },
      "additionalProperties": false
    }
  }
}
