{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://vclaw.dev/schemas/video/artifacts/cinema-production-queue.schema.json",
  "title": "CinemaProductionQueueArtifact",
  "type": "object",
  "required": ["schemaVersion", "projectSlug", "generatedAt", "tasks"],
  "additionalProperties": false,
  "properties": {
    "schemaVersion": { "const": 1 },
    "projectSlug": { "type": "string", "minLength": 1 },
    "generatedAt": { "type": "string", "format": "date-time" },
    "tasks": { "type": "array", "items": { "$ref": "#/definitions/Task" } }
  },
  "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 }
      }
    },
    "Lane": {
      "type": "object",
      "required": ["laneId", "limit", "ticketId", "ticketState", "position", "etaSeconds"],
      "additionalProperties": false,
      "properties": {
        "laneId": { "type": "string", "minLength": 1 },
        "limit": { "type": ["integer", "null"], "minimum": 1 },
        "ticketId": { "type": ["string", "null"] },
        "ticketState": { "enum": ["none", "queued", "held"] },
        "position": { "type": ["integer", "null"], "minimum": 0 },
        "etaSeconds": { "type": ["number", "null"], "minimum": 0 }
      }
    },
    "Lease": {
      "type": "object",
      "required": ["leaseId", "workerId", "acquiredAt", "expiresAt"],
      "additionalProperties": false,
      "properties": {
        "leaseId": { "type": "string", "minLength": 1 },
        "workerId": { "type": "string", "minLength": 1 },
        "acquiredAt": { "type": "string", "format": "date-time" },
        "expiresAt": { "type": "string", "format": "date-time" }
      }
    },
    "Failure": {
      "type": "object",
      "required": ["code", "message", "retryable"],
      "additionalProperties": false,
      "properties": {
        "code": { "type": "string", "minLength": 1 },
        "message": { "type": "string", "minLength": 1 },
        "retryable": { "type": "boolean" }
      }
    },
    "ProviderExecution": {
      "type": "object",
      "required": ["submissionKey", "providerJobId", "submittedAt", "lastObservedAt", "providerStatus", "providerStatusEnvelope", "providerStatusHash", "reconciliation", "download"],
      "additionalProperties": false,
      "properties": {
        "submissionKey": { "$ref": "#/definitions/Sha256" },
        "providerJobId": { "type": ["string", "null"] },
        "submittedAt": { "type": ["string", "null"], "format": "date-time" },
        "lastObservedAt": { "type": "string", "format": "date-time" },
        "providerStatus": { "type": "string", "minLength": 1 },
        "providerStatusEnvelope": { "type": "object", "additionalProperties": true },
        "providerStatusHash": { "$ref": "#/definitions/Sha256" },
        "reconciliation": {
          "type": "object",
          "required": ["required", "reason", "attempts"],
          "additionalProperties": false,
          "properties": {
            "required": { "type": "boolean" },
            "reason": { "type": ["string", "null"] },
            "attempts": { "type": "integer", "minimum": 0 }
          }
        },
        "download": {
          "type": "object",
          "required": ["temporaryPath", "finalPath", "contentHash", "byteLength", "completedAt"],
          "additionalProperties": false,
          "properties": {
            "temporaryPath": { "type": ["string", "null"] },
            "finalPath": { "type": ["string", "null"] },
            "contentHash": { "anyOf": [{ "$ref": "#/definitions/Sha256" }, { "type": "null" }] },
            "byteLength": { "type": ["integer", "null"], "minimum": 0 },
            "completedAt": { "type": ["string", "null"], "format": "date-time" }
          }
        }
      }
    },
    "Task": {
      "type": "object",
      "required": ["taskId", "kind", "executionHash", "payloadHash", "payload", "status", "dependencies", "routeId", "lane", "lease", "execution", "createdAt", "updatedAt", "estimatedCost", "actualCost", "authorizationRequirement", "spendAuthorizationId", "evidenceIds", "failure"],
      "additionalProperties": false,
      "properties": {
        "taskId": { "type": "string", "minLength": 1 },
        "kind": { "enum": ["image-generate", "image-repair", "video-generate", "audio-generate", "visual-qc", "identity-qc", "continuity-qc", "editorial-qc", "post-process", "assemble"] },
        "executionHash": { "$ref": "#/definitions/Sha256" },
        "payloadHash": { "$ref": "#/definitions/Sha256" },
        "payload": {
          "type": "object",
          "required": ["artifactIds", "parameters"],
          "additionalProperties": false,
          "properties": {
            "artifactIds": { "type": "array", "items": { "type": "string", "minLength": 1 } },
            "parameters": { "type": "object", "additionalProperties": true }
          }
        },
        "status": { "enum": ["awaiting-quote", "blocked", "ready", "waiting-lane", "leased", "submitting", "reconciling", "submitted", "polling", "downloading", "qc", "awaiting-review", "retry-ready", "dead-letter", "succeeded", "failed", "cancelled"] },
        "dependencies": { "type": "array", "items": { "type": "string", "minLength": 1 } },
        "routeId": { "type": "string", "minLength": 1 },
        "shotId": { "type": "string", "minLength": 1 },
        "attemptId": { "type": "string", "minLength": 1 },
        "lane": { "anyOf": [{ "$ref": "#/definitions/Lane" }, { "type": "null" }] },
        "lease": { "anyOf": [{ "$ref": "#/definitions/Lease" }, { "type": "null" }] },
        "execution": { "anyOf": [{ "$ref": "#/definitions/ProviderExecution" }, { "type": "null" }] },
        "createdAt": { "type": "string", "format": "date-time" },
        "updatedAt": { "type": "string", "format": "date-time" },
        "estimatedCost": { "$ref": "#/definitions/Money" },
        "actualCost": { "$ref": "#/definitions/Money" },
        "authorizationRequirement": { "enum": ["none", "exact-quote"] },
        "spendAuthorizationId": { "type": ["string", "null"] },
        "evidenceIds": { "type": "array", "items": { "type": "string", "minLength": 1 } },
        "failure": { "anyOf": [{ "$ref": "#/definitions/Failure" }, { "type": "null" }] }
      }
    }
  }
}
