{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://underautomation.com/touchup/schemas/touchup-backup.schema.json",
  "title": "TouchUp backup manifest",
  "description": "The touchup-backup.json file at the root of a TouchUp backup folder, schema version 1. Strict JSON. A reader ignores the fields it does not know: new fields are only added, and are optional, so this schema accepts additional properties everywhere. A breaking change raises schemaVersion, and a new schema describes it. The format is described at https://underautomation.com/touchup/documentation/backup-format.",
  "type": "object",
  "required": ["schemaVersion", "controller", "takenAt", "takenBy", "touchupVersion", "sdkVersion", "files"],
  "properties": {
    "schemaVersion": {
      "description": "Version of the format of this file. A reader of version 1 skips a file of another version.",
      "const": 1
    },
    "controller": { "$ref": "#/definitions/controller" },
    "takenAt": {
      "description": "When the backup was taken, ISO 8601 with an offset (UTC for a backup of TouchUp).",
      "type": "string"
    },
    "takenBy": { "description": "The OS user and the machine that took the backup, user@machine.", "type": "string" },
    "touchupVersion": { "description": "The version of TouchUp that wrote the backup.", "type": "string" },
    "sdkVersion": { "description": "The SDK that talked to the controller.", "type": "string" },
    "files": {
      "description": "The files of the controller, text and binary, below files/, as TouchUp wrote them. A binary file has no normalizedSha256.",
      "type": "array",
      "items": { "$ref": "#/definitions/file" }
    },
    "binary": {
      "description": "Optional. The binary backups below binary/ (the Yaskawa CMOS image). Compared by hash only.",
      "type": "array",
      "items": { "$ref": "#/definitions/file" }
    },
    "skipped": {
      "description": "Optional. The files the controller refused to send (or the CMOS image, path /SPDRV/CMOSBK.BIN): they are not in the backup.",
      "type": "array",
      "items": {
        "type": "object",
        "required": ["path", "reason"],
        "properties": {
          "path": { "description": "The path on the controller, not below files/.", "type": "string" },
          "reason": { "description": "The message of the controller, with secrets removed.", "type": "string" }
        }
      }
    },
    "normalization": {
      "description": "Optional. The rule set that the normalizedSha256 of the files were computed with.",
      "type": "object",
      "required": ["rules", "version"],
      "properties": {
        "rules": { "description": "The name of the rule set, for example fanuc or yaskawa.", "type": "string" },
        "version": { "type": "integer", "minimum": 1 }
      }
    },
    "profile": {
      "description": "Optional. The backup profile. A manifest without it reads as the default profile of the brand of its controller.",
      "type": "object",
      "required": ["name", "version"],
      "properties": {
        "name": {
          "description": "The name as the pendant shows it. It may change in a later TouchUp.",
          "type": "string"
        },
        "version": { "type": "integer", "minimum": 1 },
        "id": {
          "description": "Optional. The stable id of the profile, matched first (for example fanuc-all-of-above). Without it, the profile of the brand with that name.",
          "type": "string"
        }
      }
    },
    "summary": {
      "description": "Optional. What changed since the previous backup of the controller, as text.",
      "type": "string"
    }
  },
  "definitions": {
    "controller": {
      "type": "object",
      "required": ["id", "name", "brand"],
      "properties": {
        "id": { "description": "The id of the controller in the TouchUp configuration.", "type": "string" },
        "name": { "type": "string" },
        "brand": { "description": "fanuc or yaskawa.", "type": "string" },
        "model": { "type": ["string", "null"] },
        "software": { "type": ["string", "null"] },
        "serial": { "type": ["string", "null"] }
      }
    },
    "file": {
      "type": "object",
      "required": ["path", "size", "sha256"],
      "properties": {
        "path": {
          "description": "Relative to the backup folder, with /, below files/ or binary/.",
          "type": "string",
          "pattern": "^(?!.*//)(files|binary)/(?!(.*/)?\\.{1,2}(/|$))[^\\\\:]+$"
        },
        "size": { "description": "Size in bytes of the file on disk.", "type": "integer", "minimum": 0 },
        "sha256": {
          "description": "SHA-256 of the bytes of the file on disk, 64 hexadecimal digits, lowercase.",
          "type": "string",
          "pattern": "^[0-9a-f]{64}$"
        },
        "normalizedSha256": {
          "description": "Optional, text files only. SHA-256 of the normalized text (UTF-8), computed with the rules of normalization.",
          "type": "string",
          "pattern": "^[0-9a-f]{64}$"
        },
        "encoding": {
          "description": "Optional, text files that are not UTF-8 (shift_jis for most text files). No label on a text file means UTF-8.",
          "type": "string"
        }
      }
    }
  }
}
