{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://tune.toys/schemas/platform/update-manifest.schema.json",
  "title": "UpdateManifest",
  "description": "Signed update feed payload for one product and channel (tunetoys.update-manifest/1). Lists artifact digests, never URLs or tickets. Signed in a SignedEnvelope with the update_feed key.",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "schema": {
      "const": "tunetoys.update-manifest/1"
    },
    "productId": {
      "$ref": "common.schema.json#/$defs/EntityId"
    },
    "channel": {
      "$ref": "enums.schema.json#/$defs/ReleaseChannel"
    },
    "sequence": {
      "type": "integer",
      "minimum": 1,
      "maximum": 9007199254740991,
      "description": "Monotonic per product and channel."
    },
    "issuedAt": {
      "$ref": "common.schema.json#/$defs/Timestamp"
    },
    "expiresAt": {
      "$ref": "common.schema.json#/$defs/Timestamp"
    },
    "version": {
      "$ref": "#/$defs/UpdateManifestVersion"
    },
    "artifacts": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/UpdateManifestArtifact"
      },
      "maxItems": 64
    },
    "yanked": {
      "type": "array",
      "items": {
        "$ref": "common.schema.json#/$defs/EntityId"
      },
      "maxItems": 256,
      "uniqueItems": true,
      "description": "Version IDs withdrawn since the previous manifest."
    },
    "keyId": {
      "$ref": "common.schema.json#/$defs/EntityId"
    }
  },
  "required": [
    "schema",
    "productId",
    "channel",
    "sequence",
    "issuedAt",
    "expiresAt",
    "version",
    "artifacts",
    "yanked",
    "keyId"
  ],
  "$defs": {
    "UpdateManifestVersion": {
      "title": "UpdateManifestVersion",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "versionId": {
          "$ref": "common.schema.json#/$defs/EntityId"
        },
        "semver": {
          "$ref": "common.schema.json#/$defs/SemVer"
        },
        "publishedAt": {
          "$ref": "common.schema.json#/$defs/Timestamp"
        },
        "kind": {
          "type": "string",
          "enum": ["toy", "app"],
          "default": "toy",
          "description": "`app` versions (the desktop app) carry artifacts directly and pin no Toy releases, so their releaseDigests is empty. Absent means `toy`."
        },
        "releaseDigests": {
          "type": "array",
          "items": {
            "$ref": "common.schema.json#/$defs/Sha256Hex"
          },
          "maxItems": 64,
          "uniqueItems": true,
          "description": "Toy releases the version pins: at least one for a Toy version, none for an app version."
        },
        "minEngineVersion": {
          "$ref": "common.schema.json#/$defs/SemVer"
        },
        "changelogSha256": {
          "$ref": "common.schema.json#/$defs/Sha256Hex",
          "description": "Changelog text is fetched separately and checked against this digest."
        }
      },
      "required": [
        "versionId",
        "semver",
        "publishedAt",
        "releaseDigests",
        "minEngineVersion",
        "changelogSha256"
      ],
      "if": {
        "properties": {
          "kind": {
            "const": "app"
          }
        },
        "required": ["kind"]
      },
      "then": {
        "properties": {
          "releaseDigests": {
            "type": "array",
            "maxItems": 0
          }
        }
      },
      "else": {
        "properties": {
          "releaseDigests": {
            "type": "array",
            "minItems": 1
          }
        }
      }
    },
    "UpdateManifestArtifact": {
      "title": "UpdateManifestArtifact",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "artifactId": {
          "$ref": "common.schema.json#/$defs/EntityId"
        },
        "targetProfile": {
          "$ref": "enums.schema.json#/$defs/TargetProfile"
        },
        "format": {
          "$ref": "enums.schema.json#/$defs/ArtifactFormat"
        },
        "arch": {
          "$ref": "enums.schema.json#/$defs/ArtifactArch"
        },
        "size": {
          "$ref": "common.schema.json#/$defs/ByteSize"
        },
        "sha256": {
          "$ref": "common.schema.json#/$defs/Sha256Hex"
        },
        "signatureState": {
          "$ref": "enums.schema.json#/$defs/SignatureState"
        },
        "qualificationState": {
          "$ref": "enums.schema.json#/$defs/QualificationState"
        },
        "inventorySha256": {
          "$ref": "common.schema.json#/$defs/Sha256Hex"
        },
        "pluginContractDigest": {
          "$ref": "common.schema.json#/$defs/Sha256Hex"
        }
      },
      "required": [
        "artifactId",
        "targetProfile",
        "format",
        "arch",
        "size",
        "sha256",
        "signatureState",
        "qualificationState",
        "inventorySha256"
      ]
    }
  }
}
