{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://marinocg.github.io/segarecomp-patches/schema/catalog-2.schema.json",
  "title": "segarecomp-patches catalog/index.json (catalog_format 2)",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "catalog_format",
    "packages"
  ],
  "properties": {
    "catalog_format": {
      "type": "integer",
      "enum": [
        2
      ]
    },
    "packages": {
      "type": "array",
      "items": {
        "oneOf": [
          {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "id",
              "version",
              "name",
              "revision",
              "region",
              "schema_version",
              "trust",
              "executable_code",
              "package_sha256",
              "package_size",
              "package_identity",
              "source_image_sha256",
              "patched_image_sha256",
              "bps_sha256",
              "license",
              "evidence_tier",
              "gameplay",
              "supported_scope",
              "limitations",
              "asset",
              "platform",
              "source_identity_kind",
              "bios_requirement",
              "game",
              "game_path",
              "release",
              "source_revision",
              "build"
            ],
            "properties": {
              "id": {
                "type": "string",
                "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$"
              },
              "version": {
                "type": "string",
                "pattern": "^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(-[0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*)?$"
              },
              "name": {
                "type": "string",
                "minLength": 1
              },
              "revision": {
                "type": "string",
                "minLength": 1
              },
              "region": {
                "type": "string",
                "minLength": 1
              },
              "schema_version": {
                "type": "integer",
                "enum": [
                  1,
                  2
                ]
              },
              "native_abi": {
                "type": [
                  "integer",
                  "null"
                ],
                "enum": [
                  1
                ]
              },
              "capabilities": {
                "type": "array",
                "items": {
                  "type": "string",
                  "minLength": 1
                }
              },
              "trust": {
                "type": "string",
                "enum": [
                  "data-only",
                  "trusted-native-source"
                ]
              },
              "executable_code": {
                "type": "boolean"
              },
              "package_sha256": {
                "type": "string",
                "pattern": "^[0-9a-f]{64}$"
              },
              "package_size": {
                "type": "integer",
                "minimum": 1
              },
              "package_identity": {
                "type": "string",
                "pattern": "^[0-9a-f]{64}$"
              },
              "source_image_sha256": {
                "type": "string",
                "pattern": "^[0-9a-f]{64}$"
              },
              "patched_image_sha256": {
                "type": "string",
                "pattern": "^[0-9a-f]{64}$"
              },
              "bps_sha256": {
                "type": "string",
                "pattern": "^[0-9a-f]{64}$"
              },
              "native_source_sha256": {
                "type": [
                  "string",
                  "null"
                ],
                "pattern": "^[0-9a-f]{64}$"
              },
              "license": {
                "type": "string",
                "enum": [
                  "MIT",
                  "MPL-2.0",
                  "not applicable (data-only BPS)"
                ]
              },
              "evidence_tier": {
                "type": "string",
                "enum": [
                  "synthetic-only",
                  "maintainer-attested",
                  "automated"
                ]
              },
              "gameplay": {
                "type": "string",
                "minLength": 1
              },
              "supported_scope": {
                "type": "string",
                "minLength": 1
              },
              "limitations": {
                "type": "array",
                "items": {
                  "type": "string",
                  "minLength": 1
                }
              },
              "superseded_by": {
                "type": "string",
                "pattern": "^[a-z0-9]+(-[a-z0-9]+)*@(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(-[0-9A-Za-z.-]+)?$",
                "description": "Additive supersession pointer '<id>@<version>': the only field of a published entry that may be added later."
              },
              "asset": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "name",
                  "url"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "pattern": "^[a-z0-9-]+\\.segapatch$"
                  },
                  "url": {
                    "type": "string",
                    "pattern": "^https://[^\\s]+$"
                  }
                }
              },
              "platform": {
                "type": "string",
                "enum": [
                  "genesis",
                  "master-system",
                  "game-gear",
                  "sega-cd"
                ]
              },
              "source_identity_kind": {
                "type": "string",
                "enum": [
                  "cartridge-image-sha256",
                  "disc-image-identity"
                ]
              },
              "bios_requirement": {
                "type": "string",
                "enum": [
                  "none",
                  "required",
                  "optional"
                ]
              },
              "game": {
                "type": "string",
                "minLength": 1
              },
              "release": {
                "type": "string",
                "pattern": "^v(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)$"
              },
              "game_path": {
                "type": "string",
                "pattern": "^patches/[a-z0-9-]+/[a-z0-9-]+$"
              },
              "default_widescreen": {
                "type": "string"
              },
              "default_side_style": {
                "type": "string"
              },
              "widescreen_width_max": {
                "type": "integer",
                "minimum": 0
              },
              "license_declared_in_package": {
                "type": "boolean"
              },
              "source_revision": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "repository",
                  "commit"
                ],
                "properties": {
                  "repository": {
                    "type": "string",
                    "pattern": "^https://github\\.com/[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+$"
                  },
                  "commit": {
                    "type": "string",
                    "pattern": "^[0-9a-f]{40}$"
                  },
                  "tag": {
                    "type": "string",
                    "minLength": 1
                  },
                  "tag_commit": {
                    "type": "string",
                    "pattern": "^[0-9a-f]{40}$"
                  }
                }
              },
              "build": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "writer",
                  "writer_ref",
                  "deterministic"
                ],
                "properties": {
                  "writer": {
                    "type": "string",
                    "minLength": 1
                  },
                  "writer_ref": {
                    "type": "string",
                    "pattern": "^[0-9a-f]{40}$"
                  },
                  "deterministic": {
                    "type": "boolean"
                  }
                }
              },
              "source_path": {
                "type": "string",
                "pattern": "^patches/[a-z0-9-]+/[a-z0-9-]+/[a-z0-9-]+$",
                "description": "Directory of the patch's sources at source_revision.commit. Absent on entries published before the per-patch layout, whose sources were under game_path."
              }
            },
            "description": "A schema 1 or 2 package: a BPS delta against an exact image, optionally with native C11 source. Identical to catalog_format 1."
          },
          {
            "type": "object",
            "additionalProperties": false,
            "description": "A schema 3 / native ABI 2 mod package. It has no BPS delta, no patched image digest and no single source image: `images` lists the exact images it targets.",
            "required": [
              "id",
              "version",
              "name",
              "platform",
              "source_identity_kind",
              "bios_requirement",
              "game",
              "game_path",
              "source_path",
              "release",
              "schema_version",
              "native_abi",
              "capabilities",
              "trust",
              "executable_code",
              "package_sha256",
              "package_size",
              "package_identity",
              "images",
              "license",
              "evidence_tier",
              "gameplay",
              "supported_scope",
              "limitations",
              "asset",
              "source_revision",
              "build"
            ],
            "properties": {
              "platform": {
                "type": "string",
                "enum": [
                  "genesis",
                  "master-system",
                  "game-gear",
                  "sega-cd"
                ]
              },
              "source_identity_kind": {
                "type": "string",
                "enum": [
                  "cartridge-image-sha256",
                  "disc-image-identity"
                ]
              },
              "bios_requirement": {
                "type": "string",
                "enum": [
                  "none",
                  "required",
                  "optional"
                ]
              },
              "game": {
                "type": "string",
                "minLength": 1
              },
              "game_path": {
                "type": "string",
                "pattern": "^patches/[a-z0-9-]+/[a-z0-9-]+$"
              },
              "release": {
                "type": "string",
                "pattern": "^v(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)$"
              },
              "source_revision": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "repository",
                  "commit"
                ],
                "properties": {
                  "repository": {
                    "type": "string",
                    "pattern": "^https://github\\.com/[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+$"
                  },
                  "commit": {
                    "type": "string",
                    "pattern": "^[0-9a-f]{40}$"
                  },
                  "tag": {
                    "type": "string",
                    "minLength": 1
                  },
                  "tag_commit": {
                    "type": "string",
                    "pattern": "^[0-9a-f]{40}$"
                  }
                }
              },
              "build": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "writer",
                  "writer_ref",
                  "deterministic"
                ],
                "properties": {
                  "writer": {
                    "type": "string",
                    "minLength": 1
                  },
                  "writer_ref": {
                    "type": "string",
                    "pattern": "^[0-9a-f]{40}$"
                  },
                  "deterministic": {
                    "type": "boolean"
                  }
                }
              },
              "asset": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "name",
                  "url"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "pattern": "^[a-z0-9-]+\\.segapatch$"
                  },
                  "url": {
                    "type": "string",
                    "pattern": "^https://[^\\s]+$"
                  }
                }
              },
              "superseded_by": {
                "type": "string",
                "pattern": "^[a-z0-9]+(-[a-z0-9]+)*@(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(-[0-9A-Za-z.-]+)?$",
                "description": "Additive supersession pointer '<id>@<version>': the only field of a published entry that may be added later."
              },
              "id": {
                "type": "string",
                "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$"
              },
              "version": {
                "type": "string",
                "pattern": "^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(-[0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*)?$"
              },
              "name": {
                "type": "string",
                "minLength": 1
              },
              "license": {
                "type": "string",
                "enum": [
                  "MIT",
                  "MPL-2.0"
                ],
                "description": "A schema 3 package carries executable native source, so only an established open license with its text in this repository is accepted."
              },
              "evidence_tier": {
                "type": "string",
                "enum": [
                  "synthetic-only",
                  "maintainer-attested",
                  "automated"
                ]
              },
              "gameplay": {
                "type": "string",
                "minLength": 1
              },
              "supported_scope": {
                "type": "string",
                "minLength": 1
              },
              "limitations": {
                "type": "array",
                "items": {
                  "type": "string",
                  "minLength": 1
                }
              },
              "package_sha256": {
                "type": "string",
                "pattern": "^[0-9a-f]{64}$"
              },
              "package_size": {
                "type": "integer",
                "minimum": 1
              },
              "package_identity": {
                "type": "string",
                "pattern": "^[0-9a-f]{64}$"
              },
              "capabilities": {
                "type": "array",
                "minItems": 1,
                "items": {
                  "type": "string",
                  "minLength": 1
                }
              },
              "trust": {
                "type": "string",
                "enum": [
                  "trusted-native-source"
                ]
              },
              "executable_code": {
                "type": "boolean",
                "enum": [
                  true
                ]
              },
              "source_path": {
                "type": "string",
                "pattern": "^patches/[a-z0-9-]+/[a-z0-9-]+/[a-z0-9-]+$",
                "description": "Directory of the patch's sources at source_revision.commit. Absent on entries published before the per-patch layout, whose sources were under game_path."
              },
              "schema_version": {
                "type": "integer",
                "enum": [
                  3
                ]
              },
              "native_abi": {
                "type": "integer",
                "enum": [
                  2
                ]
              },
              "images": {
                "type": "array",
                "minItems": 1,
                "description": "The exact cartridge images this package declares itself compatible with (mod.toml [[target.revision]]); an image is identified by its SHA-256, never by title or region.",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "label",
                    "sha256"
                  ],
                  "properties": {
                    "label": {
                      "type": "string",
                      "minLength": 1
                    },
                    "sha256": {
                      "type": "string",
                      "pattern": "^[0-9a-f]{64}$"
                    }
                  }
                }
              }
            }
          }
        ]
      }
    }
  },
  "description": "catalog_format 2 = catalog_format 1 plus schema 3 mod entries. Entries with schema_version 1 or 2 are exactly the format 1 entries; a reader that only understands format 1 must refuse this file (it rejects the unknown catalog_format) instead of misreading a mod entry."
}
