{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://vclaw.dev/schemas/video/artifacts/narration.schema.json",
  "title": "NarrationArtifact",
  "type": "object",
  "required": ["schemaVersion", "projectSlug", "generatedAt", "backendId", "text", "path", "durationMs"],
  "additionalProperties": false,
  "properties": {
    "schemaVersion": { "const": 1 },
    "projectSlug": { "type": "string", "minLength": 1 },
    "generatedAt": { "type": "string", "format": "date-time" },
    "backendId": { "type": "string", "minLength": 1 },
    "voice": { "type": "string", "minLength": 1 },
    "text": { "type": "string", "minLength": 1 },
    "path": {
      "type": "string",
      "minLength": 1,
      "description": "Project-relative path to the generated narration audio."
    },
    "durationMs": { "type": "number", "minimum": 0 },
    "fallbackFrom": {
      "type": "array",
      "items": { "type": "string", "minLength": 1 },
      "minItems": 1,
      "description": "Backends that failed (in order) before backendId succeeded, when the automatic fallback chain was used. Omitted when the first backend succeeded or an explicit --backend was given."
    },
    "fit": { "$ref": "#/definitions/NarrationFitPlan" }
  },
  "definitions": {
    "NarrationFitPlan": {
      "type": "object",
      "required": ["tempo", "loopVideo", "targetDurationMs", "warnings"],
      "additionalProperties": false,
      "description": "Pure narration/video timing fit plan (from planNarrationFit). Present only when a videoDurationMs was supplied.",
      "properties": {
        "tempo": { "type": "number", "minimum": 1, "description": "FFmpeg atempo value for narration." },
        "loopVideo": { "type": "boolean", "description": "Whether the visual bed must be looped/extended." },
        "targetDurationMs": { "type": "number", "minimum": 0, "description": "Exact mixed output duration to cap with ffmpeg -t." },
        "warnings": {
          "type": "array",
          "items": {
            "type": "object",
            "required": ["code", "message"],
            "additionalProperties": false,
            "properties": {
              "code": { "enum": ["voice-speedup-applied", "voice-too-long-loop-video"] },
              "message": { "type": "string" }
            }
          }
        }
      }
    }
  }
}
