{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://bhopstudio.com/floodtide/standards/update-manifest/v1/schema.json",
  "title": "Floodtide App Update Manifest Draft, version 1",
  "type": "object",
  "required": ["schemaVersion", "applications"],
  "additionalProperties": false,
  "properties": {
    "schemaVersion": { "const": 1 },
    "applications": {
      "type": "array",
      "minItems": 1,
      "maxItems": 500,
      "items": { "$ref": "#/$defs/application" }
    }
  },
  "$defs": {
    "httpsURL": {
      "type": "string",
      "format": "uri",
      "pattern": "^[Hh][Tt][Tt][Pp][Ss]://(?![^/?#]*@)[^\\s/?#]+(?:[/?#][^\\s]*)?$"
    },
    "application": {
      "type": "object",
      "required": ["bundleIdentifier", "name", "status", "homepage"],
      "additionalProperties": false,
      "properties": {
        "bundleIdentifier": {
          "type": "string",
          "maxLength": 255,
          "pattern": "^[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?(?:\\.[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?)+$"
        },
        "name": { "type": "string", "minLength": 1, "maxLength": 255, "pattern": "\\S" },
        "status": { "enum": ["active", "maintenance", "discontinued"] },
        "homepage": { "$ref": "#/$defs/httpsURL" },
        "repository": { "$ref": "#/$defs/httpsURL" },
        "update": { "$ref": "#/$defs/update" }
      },
      "allOf": [
        {
          "if": {
            "required": ["status"],
            "properties": { "status": { "const": "discontinued" } }
          },
          "then": {
            "not": {
              "required": ["update"],
              "properties": { "update": {} }
            }
          },
          "else": {
            "required": ["update"],
            "properties": { "update": {} }
          }
        }
      ]
    },
    "update": {
      "type": "object",
      "oneOf": [
        {
          "required": ["sparkle"],
          "additionalProperties": false,
          "properties": { "sparkle": { "$ref": "#/$defs/httpsURL" } }
        },
        {
          "required": ["github"],
          "additionalProperties": false,
          "properties": {
            "github": {
              "type": "string",
              "format": "uri",
              "pattern": "^[Hh][Tt][Tt][Pp][Ss]://(?![^/?#]*@)[Gg][Ii][Tt][Hh][Uu][Bb]\\.[Cc][Oo][Mm]/[^\\s/?#]+/[^\\s/?#]+(?:[/?#][^\\s]*)?$"
            }
          }
        },
        {
          "required": ["release"],
          "additionalProperties": false,
          "properties": { "release": { "$ref": "#/$defs/release" } }
        }
      ]
    },
    "release": {
      "type": "object",
      "required": ["version", "downloadURL"],
      "additionalProperties": false,
      "properties": {
        "version": { "type": "string", "minLength": 1, "maxLength": 100, "pattern": "\\S" },
        "build": { "type": "string", "minLength": 1, "maxLength": 100, "pattern": "\\S" },
        "downloadURL": { "$ref": "#/$defs/httpsURL" },
        "releaseNotesURL": { "$ref": "#/$defs/httpsURL" },
        "publishedAt": {
          "type": "string",
          "format": "date-time",
          "pattern": "^\\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\\d|3[01])[Tt](?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:[Zz]|[+-](?:[01]\\d|2[0-3]):[0-5]\\d)$"
        },
        "minimumSystemVersion": {
          "type": "string",
          "pattern": "^\\d+(?:\\.\\d+){0,3}$"
        },
        "architectures": {
          "type": "array",
          "minItems": 1,
          "maxItems": 3,
          "uniqueItems": true,
          "items": { "enum": ["arm64", "x86_64", "universal"] }
        },
        "sha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" }
      }
    }
  }
}
