{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://promptedllc.com/schemas/utas-sequence-manifest.schema.json",
  "title": "UTAS sequence manifest",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema",
    "sequence_id",
    "slug",
    "version",
    "state",
    "work",
    "policies",
    "asset_bindings",
    "segments",
    "transitions",
    "markers"
  ],
  "properties": {
    "schema": {
      "const": "prompted.utas.sequence-manifest.v1"
    },
    "sequence_id": {
      "type": "string",
      "minLength": 1
    },
    "slug": {
      "type": "string",
      "pattern": "^[a-z0-9][a-z0-9._-]*$"
    },
    "version": {
      "type": "integer",
      "minimum": 1
    },
    "state": {
      "enum": ["draft", "review", "admitted", "published", "retired"]
    },
    "supersedes_sequence_id": {
      "type": ["string", "null"]
    },
    "manifest_sha256": {
      "anyOf": [
        { "$ref": "#/$defs/sha256" },
        { "type": "null" }
      ]
    },
    "work": {
      "type": "object",
      "additionalProperties": false,
      "required": ["work_id", "title", "act_id", "act_title"],
      "properties": {
        "work_id": { "type": "string" },
        "title": { "type": "string" },
        "act_id": { "type": "string" },
        "act_title": { "type": "string" },
        "dramaturgical_note": { "type": "string" }
      }
    },
    "entry_context": {
      "type": ["object", "null"],
      "additionalProperties": false,
      "required": ["from_sequence_id", "from_segment_id", "from_marker_id", "transition"],
      "properties": {
        "from_sequence_id": { "type": "string" },
        "from_segment_id": { "type": "string" },
        "from_marker_id": { "type": "string" },
        "transition": { "$ref": "#/$defs/transition" }
      }
    },
    "policies": {
      "type": "object",
      "additionalProperties": false,
      "required": ["continuous_play", "skip_pending", "unavailable_asset", "resume_version_drift"],
      "properties": {
        "continuous_play": {
          "enum": ["stop_on_authored_gap", "continue_only_through_admitted_transitions"]
        },
        "skip_pending": {
          "const": "explicit_only"
        },
        "unavailable_asset": {
          "const": "buffer_hold_with_reason"
        },
        "resume_version_drift": {
          "const": "map_stable_ids_and_confirm"
        }
      }
    },
    "asset_bindings": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["media_asset_id", "role", "availability"],
        "properties": {
          "media_asset_id": { "type": "string" },
          "role": { "enum": ["movement", "bridge", "stitched_authority", "threshold", "other"] },
          "availability": { "enum": ["pending", "ready", "verified", "withdrawn", "unavailable"] },
          "expected_derivative_sha256": {
            "anyOf": [
              { "$ref": "#/$defs/sha256" },
              { "type": "null" }
            ]
          }
        }
      }
    },
    "segments": {
      "type": "array",
      "minItems": 1,
      "items": { "$ref": "#/$defs/segment" }
    },
    "transitions": {
      "type": "array",
      "items": { "$ref": "#/$defs/transition" }
    },
    "markers": {
      "type": "array",
      "items": { "$ref": "#/$defs/marker" }
    }
  },
  "$defs": {
    "sha256": {
      "type": "string",
      "pattern": "^[a-f0-9]{64}$"
    },
    "cue": {
      "type": "object",
      "additionalProperties": false,
      "required": ["segment_id", "carrier_seconds"],
      "properties": {
        "segment_id": { "type": "string" },
        "carrier_seconds": { "type": "number", "minimum": 0 }
      }
    },
    "segment": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "segment_id",
        "order",
        "title",
        "role",
        "admission_status",
        "availability",
        "media_asset_id",
        "carrier_range",
        "cues",
        "lane_contract_ref"
      ],
      "properties": {
        "segment_id": { "type": "string", "minLength": 1 },
        "order": { "type": "integer", "minimum": 0 },
        "title": { "type": "string", "minLength": 1 },
        "role": { "enum": ["movement", "bridge", "blackout", "threshold", "other"] },
        "admission_status": { "enum": ["pending", "held", "admitted", "rejected", "retired"] },
        "availability": { "enum": ["pending", "ready", "unavailable", "withdrawn"] },
        "media_asset_id": { "type": ["string", "null"] },
        "carrier_range": {
          "type": "object",
          "additionalProperties": false,
          "required": ["in_seconds", "out_seconds"],
          "properties": {
            "in_seconds": { "type": ["number", "null"], "minimum": 0 },
            "out_seconds": { "type": ["number", "null"], "exclusiveMinimum": 0 }
          }
        },
        "cues": {
          "type": "object",
          "additionalProperties": false,
          "required": ["canonical_start_seconds", "navigation_seek_seconds", "label_time_seconds", "navigation_preroll_seconds"],
          "properties": {
            "canonical_start_seconds": { "type": ["number", "null"], "minimum": 0 },
            "navigation_seek_seconds": { "type": ["number", "null"], "minimum": 0 },
            "label_time_seconds": { "type": ["number", "null"], "minimum": 0 },
            "navigation_preroll_seconds": { "type": "number", "minimum": 0 }
          }
        },
        "lane_contract_ref": { "type": ["string", "null"] },
        "dramaturgical_role": { "type": "string" },
        "technical_notes": { "type": "array", "items": { "type": "string" } }
      }
    },
    "transition": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "transition_id",
        "from_segment_id",
        "to_segment_id",
        "type",
        "admission_status",
        "bridge_media_asset_id",
        "timing",
        "lane_law",
        "hold_behavior"
      ],
      "properties": {
        "transition_id": { "type": "string" },
        "from_segment_id": { "type": "string" },
        "to_segment_id": { "type": "string" },
        "type": {
          "enum": [
            "continuous_same_asset",
            "embedded_hinge",
            "dedicated_bridge_asset",
            "explicit_cut",
            "protected_blackout",
            "bridge_pending"
          ]
        },
        "admission_status": { "enum": ["pending", "held", "admitted", "retired"] },
        "bridge_media_asset_id": { "type": ["string", "null"] },
        "timing": {
          "type": "object",
          "additionalProperties": false,
          "required": ["approach_start", "technical_boundary", "handoff_complete", "authored_overlap_seconds"],
          "properties": {
            "approach_start": { "anyOf": [{ "$ref": "#/$defs/cue" }, { "type": "null" }] },
            "technical_boundary": { "anyOf": [{ "$ref": "#/$defs/cue" }, { "type": "null" }] },
            "handoff_complete": { "anyOf": [{ "$ref": "#/$defs/cue" }, { "type": "null" }] },
            "authored_overlap_seconds": { "type": "number", "minimum": 0 },
            "authored_overlap_curve": { "type": ["string", "null"] }
          }
        },
        "lane_law": {
          "type": "object",
          "additionalProperties": false,
          "required": ["persist", "change", "sever", "handoff"],
          "properties": {
            "persist": { "type": "array", "items": { "type": "string" } },
            "change": { "type": "array", "items": { "type": "string" } },
            "sever": { "type": "array", "items": { "type": "string" } },
            "handoff": { "type": "array", "items": { "type": "string" } }
          }
        },
        "hold_behavior": {
          "type": "object",
          "additionalProperties": false,
          "required": ["when_unresolved", "auto_continue", "next_available_requires_acknowledgment"],
          "properties": {
            "when_unresolved": { "const": "freeze_artistic_time_preserve_witness_and_o4" },
            "auto_continue": { "type": "boolean" },
            "next_available_requires_acknowledgment": { "const": true }
          }
        },
        "protected_event_note": { "type": ["string", "null"] }
      }
    },
    "marker": {
      "type": "object",
      "additionalProperties": false,
      "required": ["marker_id", "type", "segment_id", "title", "cue", "seek", "story_job", "load_bearing"],
      "properties": {
        "marker_id": { "type": "string" },
        "type": {
          "enum": [
            "movement_start",
            "song_identity",
            "phase",
            "load_bearing_moment",
            "transition_boundary",
            "orientation_return"
          ]
        },
        "segment_id": { "type": "string" },
        "title": { "type": "string" },
        "cue": { "$ref": "#/$defs/cue" },
        "seek": {
          "type": "object",
          "additionalProperties": false,
          "required": ["target_seconds", "preroll_seconds"],
          "properties": {
            "target_seconds": { "type": "number", "minimum": 0 },
            "preroll_seconds": { "type": "number", "minimum": 0 }
          }
        },
        "story_job": { "type": "string" },
        "load_bearing": { "type": "array", "items": { "type": "string" } },
        "frame_ref": { "type": ["string", "null"] }
      }
    }
  }
}

