{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://vclaw.dev/schemas/video/artifacts/cinema-generation-ledger.schema.json",
  "title": "CinemaGenerationLedgerArtifact",
  "type": "object",
  "required": ["schemaVersion", "projectSlug", "generatedAt", "attempts", "promotions"],
  "additionalProperties": false,
  "properties": {
    "schemaVersion": { "const": 1 },
    "projectSlug": { "type": "string", "minLength": 1 },
    "generatedAt": { "type": "string", "format": "date-time" },
    "attempts": { "type": "array", "items": { "$ref": "#/definitions/Attempt" } },
    "outcomes": { "type": "array", "items": { "$ref": "#/definitions/Outcome" } },
    "promotions": { "type": "array", "items": { "$ref": "#/definitions/Promotion" } }
  },
  "definitions": {
    "Sha256": { "type": "string", "pattern": "^sha256:[a-f0-9]{64}$" },
    "Money": {
      "type": "object",
      "required": ["currency", "amount"],
      "additionalProperties": false,
      "properties": {
        "currency": { "type": "string", "minLength": 1 },
        "amount": { "type": "number", "minimum": 0 }
      }
    },
    "Attempt": {
      "type": "object",
      "required": ["attemptId", "shotId", "parentAttemptId", "payloadHash", "routeId", "status", "preparedAt", "changedVariables", "failureTags", "evidenceIds", "estimatedCost", "actualCost"],
      "additionalProperties": false,
      "properties": {
        "attemptId": { "type": "string", "minLength": 1 },
        "shotId": { "type": "string", "minLength": 1 },
        "parentAttemptId": { "type": ["string", "null"] },
        "payloadHash": { "$ref": "#/definitions/Sha256" },
        "routeId": { "type": "string", "minLength": 1 },
        "status": { "enum": ["prepared", "dry-run-complete", "submitted", "completed", "failed", "cancelled"] },
        "preparedAt": { "type": "string", "format": "date-time" },
        "completedAt": { "type": "string", "format": "date-time" },
        "providerJobId": { "type": "string", "minLength": 1 },
        "changedVariables": { "type": "array", "items": { "type": "string", "minLength": 1 } },
        "failureTags": { "type": "array", "items": { "type": "string", "minLength": 1 } },
        "evidenceIds": { "type": "array", "items": { "type": "string", "minLength": 1 } },
        "estimatedCost": { "$ref": "#/definitions/Money" },
        "actualCost": { "$ref": "#/definitions/Money" }
      }
    },
    "Outcome": {
      "type": "object",
      "required": ["outcomeId", "attemptId", "shotId", "queueTaskId", "executionHash", "payloadHash", "status", "observedAt", "providerJobId", "media", "actualCost", "evidenceIds", "contentHash"],
      "additionalProperties": false,
      "properties": {
        "outcomeId": { "type": "string", "minLength": 1 },
        "attemptId": { "type": "string", "minLength": 1 },
        "shotId": { "type": "string", "minLength": 1 },
        "queueTaskId": { "type": "string", "minLength": 1 },
        "executionHash": { "$ref": "#/definitions/Sha256" },
        "payloadHash": { "$ref": "#/definitions/Sha256" },
        "status": { "const": "completed" },
        "observedAt": { "type": "string", "format": "date-time" },
        "providerJobId": { "type": "string", "minLength": 1 },
        "media": {
          "type": "object",
          "required": ["path", "contentHash", "byteLength"],
          "additionalProperties": false,
          "properties": {
            "path": { "type": "string", "minLength": 1 },
            "contentHash": { "$ref": "#/definitions/Sha256" },
            "byteLength": { "type": "integer", "minimum": 1 }
          }
        },
        "actualCost": { "$ref": "#/definitions/Money" },
        "evidenceIds": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "type": "string", "minLength": 1 } },
        "contentHash": { "$ref": "#/definitions/Sha256" }
      }
    },
    "Promotion": {
      "type": "object",
      "required": ["promotionId", "shotId", "attemptId", "reviewerId", "editorialSlot", "decidedAt", "supersedesPromotionId", "evidenceIds", "storyPurposeVerified"],
      "additionalProperties": false,
      "properties": {
        "promotionId": { "type": "string", "minLength": 1 },
        "shotId": { "type": "string", "minLength": 1 },
        "attemptId": { "type": "string", "minLength": 1 },
        "reviewerId": { "type": "string", "minLength": 1 },
        "editorialSlot": { "type": "string", "minLength": 1 },
        "decidedAt": { "type": "string", "format": "date-time" },
        "supersedesPromotionId": { "type": ["string", "null"] },
        "evidenceIds": { "type": "array", "minItems": 1, "items": { "type": "string", "minLength": 1 } },
        "storyPurposeVerified": { "const": true }
      }
    }
  }
}
