{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://trove.local/schemas/source-index.schema.json",
  "title": "Trove Source Index v1",
  "type": "object",
  "required": ["schemaVersion", "id", "name", "generatedAt", "curios"],
  "properties": {
    "schemaVersion": { "const": 1 },
    "id": {
      "type": "string",
      "minLength": 1,
      "maxLength": 100,
      "pattern": "^[a-z0-9][a-z0-9._-]*$"
    },
    "name": { "type": "string", "minLength": 1, "maxLength": 100 },
    "generatedAt": { "type": "string", "format": "date-time" },
    "curios": {
      "type": "array",
      "items": { "$ref": "#/$defs/curio" },
      "maxItems": 100000
    },
    "signature": {
      "type": "object",
      "required": ["algorithm", "keyId", "value"],
      "properties": {
        "algorithm": { "const": "ed25519" },
        "keyId": { "type": "string", "minLength": 1, "maxLength": 200 },
        "value": { "type": "string", "minLength": 1 }
      },
      "additionalProperties": false
    }
  },
  "additionalProperties": false,
  "$defs": {
    "curio": {
      "type": "object",
      "required": ["id", "name", "versions"],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9.-]*[a-z0-9]$",
          "maxLength": 160
        },
        "name": { "type": "string", "minLength": 1, "maxLength": 100 },
        "description": { "type": "string", "maxLength": 1000 },
        "icon": { "type": "string", "format": "uri" },
        "versions": {
          "type": "array",
          "items": { "$ref": "#/$defs/version" },
          "minItems": 1
        }
      },
      "additionalProperties": false
    },
    "version": {
      "type": "object",
      "required": ["version", "engine", "releasedAt", "artifacts"],
      "properties": {
        "version": { "$ref": "#/$defs/semver" },
        "engine": {
          "type": "object",
          "required": ["trove"],
          "properties": {
            "trove": { "type": "string", "minLength": 1, "maxLength": 100 }
          },
          "additionalProperties": false
        },
        "releasedAt": { "type": "string", "format": "date-time" },
        "artifacts": {
          "type": "array",
          "items": { "$ref": "#/$defs/artifact" },
          "minItems": 1,
          "maxItems": 8
        }
      },
      "additionalProperties": false
    },
    "artifact": {
      "type": "object",
      "required": ["target", "url", "sha256", "size"],
      "properties": {
        "target": {
          "type": "string",
          "enum": ["any", "aarch64-apple-darwin", "x86_64-apple-darwin"]
        },
        "url": { "type": "string", "format": "uri-reference", "description": "Absolute HTTP(S)/file URL, or a safe path relative to source/index.json for Git sources." },
        "sha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
        "size": { "type": "integer", "minimum": 1 }
      },
      "additionalProperties": false
    },
    "semver": {
      "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.-]+)?$"
    }
  }
}
