{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://code-as-usual.invalid/schemas/installation-package-template-v2.schema.json",
  "title": "Code as Usual installation package template",
  "type": "object",
  "additionalProperties": false,
  "required": ["format", "formatVersion", "templateName", "templateDescription", "parameters", "definition"],
  "properties": {
    "format": {"const": "code-as-usual.installation-package-template"},
    "formatVersion": {"const": 2},
    "templateName": {"type": "string", "minLength": 1},
    "templateDescription": {"type": "string", "minLength": 1},
    "parameters": {
      "type": "array",
      "items": {"$ref": "#/$defs/parameter"}
    },
    "definition": {"$ref": "#/$defs/definition"}
  },
  "$defs": {
    "parameter": {
      "type": "object",
      "additionalProperties": false,
      "required": ["key", "label", "help", "inputType", "required", "defaultValue", "example"],
      "properties": {
        "key": {"type": "string", "pattern": "^[a-z][a-zA-Z0-9]*$"},
        "label": {"type": "string", "minLength": 1},
        "help": {"type": "string", "minLength": 1},
        "inputType": {"enum": ["text", "version", "url", "checksum", "path"]},
        "required": {"type": "boolean"},
        "defaultValue": {"type": "string"},
        "example": {"type": "string"}
      }
    },
    "definition": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "packageKey", "versionLabel", "name", "description", "installationMethod",
        "operatingSystemPackages", "sourceUrl", "checksumAlgorithm", "checksum",
        "archiveFormat", "extractionDirectory", "executableLinks", "environment",
        "validationCommand", "usageGuide", "capabilities", "requirements", "networkDestinations"
      ],
      "properties": {
        "packageKey": {"type": "string"},
        "versionLabel": {"type": "string"},
        "name": {"type": "string"},
        "description": {"type": "string"},
        "installationMethod": {"enum": ["ARCHIVE", "APT"]},
        "operatingSystemPackages": {"$ref": "#/$defs/stringArray"},
        "sourceUrl": {"type": "string"},
        "checksumAlgorithm": {"type": "string"},
        "checksum": {"type": "string"},
        "archiveFormat": {"type": "string"},
        "extractionDirectory": {"type": "string"},
        "executableLinks": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["sourcePath", "targetPath"],
            "properties": {
              "sourcePath": {"type": "string"},
              "targetPath": {"type": "string"}
            }
          }
        },
        "environment": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["name", "value"],
            "properties": {
              "name": {"type": "string"},
              "value": {"type": "string"}
            }
          }
        },
        "validationCommand": {"$ref": "#/$defs/stringArray"},
        "usageGuide": {"type": "string", "maxLength": 32000},
        "capabilities": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["key", "version"],
            "properties": {
              "key": {"type": "string"},
              "version": {"type": "string"}
            }
          }
        },
        "requirements": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["key", "versionConstraint"],
            "properties": {
              "key": {"type": "string"},
              "versionConstraint": {"type": "string"}
            }
          }
        },
        "networkDestinations": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["key", "name", "description", "endpointHost"],
            "properties": {
              "key": {"type": "string"},
              "name": {"type": "string"},
              "description": {"type": "string"},
              "endpointHost": {"type": "string"}
            }
          }
        }
      }
    },
    "stringArray": {
      "type": "array",
      "items": {"type": "string"}
    }
  }
}
