{
  "openapi": "3.1.0",
  "info": {
    "title": "Lock Wait public data",
    "version": "1.0.0",
    "description": "Read-only JSON snapshots of U.S. navigation lock traffic and status. Traffic and status originate from the U.S. Army Corps of Engineers Lock Performance Monitoring System; lock dimensions and coordinates include BTS NTAD data. Lock Wait archives and republishes observations and is not affiliated with the Corps. The `generated` timestamp records a Lock Wait site build, not a successful Corps observation. For a current queue, require health.healthy=true, health.lastStatus no more than 45 minutes old, and the lock status `t` no more than 60 minutes old, all judged against the reader's clock. When those conditions fail, queue values are historical last reports, not current conditions. Static files may continue to rebuild while the Corps feed is unavailable."
  },
  "servers": [{"url": "https://lockwait.com"}],
  "paths": {
    "/data/index.json": {
      "get": {
        "operationId": "getLockIndex",
        "summary": "Lock summaries and archive coverage",
        "description": "The index is rebuilt about every 15 minutes from archived data. Check /data/health.json and each lock's status time before using a queue as current. `statusStale` is the builder's verdict at build time and can age while a client keeps the file open.",
        "responses": {
          "200": {
            "description": "Current published index, which can contain historical status values during a source outage.",
            "content": {"application/json": {"schema": {"$ref": "#/components/schemas/LockIndex"}}}
          }
        }
      }
    },
    "/data/health.json": {
      "get": {
        "operationId": "getCollectionHealth",
        "summary": "Collector and source freshness",
        "description": "`healthy` and `lastStatusAgeMin` are computed when this file is written. Recalculate freshness from `lastStatus` at request time; do not treat a newer `generated` value as a newer Corps status.",
        "responses": {
          "200": {
            "description": "Latest published health report.",
            "content": {"application/json": {"schema": {"$ref": "#/components/schemas/CollectionHealth"}}}
          }
        }
      }
    },
    "/data/locks/{lockId}.json": {
      "get": {
        "operationId": "getLockArchive",
        "summary": "One lock's archived observations and traffic",
        "description": "`status` is an array of collected snapshots; its last element is the latest report for this lock, which may be stale. `lockageRows` are positional arrays whose columns are listed in `lockageFields`. Wait is arrival to start of lockage in hours for commercial tows; it is a Lock Wait calculation, not an official Corps wait figure.",
        "parameters": [{
          "name": "lockId", "in": "path", "required": true,
          "description": "Lock identifier from the index, for example OH-79.",
          "schema": {"type": "string"}
        }],
        "responses": {
          "200": {
            "description": "The published archive for this lock.",
            "content": {"application/json": {"schema": {"$ref": "#/components/schemas/LockArchive"}}}
          },
          "404": {"description": "No published archive has this lock identifier."}
        }
      }
    },
    "/data/quiet/{lockId}.json": {
      "get": {
        "operationId": "getPublishedQuietModel",
        "summary": "Historical commercial wait by weekday and arrival hour",
        "description": "Derived from archived commercial lockages in Corps-reported lock-local time. Not current conditions or navigation advice. Compare generated with the index to avoid mixing builds.",
        "parameters": [{"name": "lockId", "in": "path", "required": true, "schema": {"type": "string"}}],
        "responses": {"200": {"description": "Published historical model.", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/QuietModel"}}}},
                      "404": {"description": "No model for this lock."}}
      }
    },
    "/api/quiet/{lockId}": {
      "get": {
        "operationId": "getVerifiedQuietModel",
        "summary": "Generation-checked historical wait model",
        "description": "Anonymous, rate-limited API. Rejects a model from a different site build. A low-wait candidate is historical and does not verify future operating hours or closures.",
        "parameters": [{"name": "lockId", "in": "path", "required": true, "schema": {"type": "string"}}],
        "responses": {"200": {"description": "Historical model.", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/QuietModel"}}}},
                      "404": {"description": "Unknown lock."}, "429": {"description": "Hourly request limit reached."},
                      "503": {"description": "Published model is unavailable or disagrees with the index."}}
      }
    }
  },
  "components": {
    "schemas": {
      "StatusObservation": {
        "type": "object",
        "required": ["t"],
        "properties": {
          "t": {"type": "string", "format": "date-time", "description": "Lock Wait collection time in UTC; this is the queue observation time to check for freshness."},
          "entry": {"type": ["string", "null"], "description": "Corps status report time in lock-local time."},
          "pending": {"type": ["integer", "null"], "description": "Tows pending at this observation, not necessarily waiting now."},
          "locking": {"type": ["integer", "null"]},
          "avg4h": {"type": ["number", "null"], "description": "Corps four-hour average delay in minutes, distinct from Lock Wait arrival-to-lockage wait."},
          "stall": {"type": ["boolean", "null"]},
          "notices": {"type": "array", "items": {"type": "string"}}
        },
        "additionalProperties": true
      },
      "AlternateReport": {
        "type": "object",
        "description": "A dated observation from a separate partial Corps per-river route. It is not a current queue or national status recovery.",
        "required": ["source", "pending", "reportedLocal", "collectedAtUtc", "delay24hMinutes"],
        "properties": {
          "source": {"const": "corps_legacy_per_river"},
          "pending": {"type": "integer", "minimum": 0},
          "reportedLocal": {"type": "string", "description": "Lock-local reading time with no verified UTC offset."},
          "collectedAtUtc": {"type": "string", "format": "date-time"},
          "delay24hMinutes": {"type": ["number", "null"], "description": "Separate 24-hour delay; never the national feed's 4-hour measure."}
        },
        "additionalProperties": false
      },
      "RiverGlance": {
        "type": "object",
        "description": "Dated arrival records from the separate Corps River at a Glance feed. Missing end times do not establish a current queue.",
        "required": ["source", "observationDateLocal", "arrivals", "withoutEndTime", "collectedAtUtc"],
        "properties": {
          "source": {"const": "corps_river_at_a_glance"},
          "observationDateLocal": {"type": "string", "format": "date"},
          "arrivals": {"type": "integer", "minimum": 0},
          "withoutEndTime": {"type": "integer", "minimum": 0},
          "collectedAtUtc": {"type": "string", "format": "date-time"}
        },
        "additionalProperties": false
      },
      "SeparateDelay": {
        "type": "object",
        "description": "Separately collected Corps delay averages without a source measurement timestamp; not current status.",
        "required": ["source", "delay4hMinutes", "delay24hMinutes", "collectedAtUtc"],
        "properties": {
          "source": {"const": "corps_separate_delay_report"},
          "delay4hMinutes": {"type": ["integer", "null"], "minimum": 0},
          "delay24hMinutes": {"type": ["integer", "null"], "minimum": 0},
          "collectedAtUtc": {"type": "string", "format": "date-time"}
        },
        "additionalProperties": false
      },
      "LockSummary": {
        "type": "object",
        "required": ["id", "name", "riverName", "lockages", "status"],
        "properties": {
          "id": {"type": "string"},
          "name": {"type": "string"},
          "riverName": {"type": "string"},
          "state": {"type": ["string", "null"]},
          "riverMile": {"type": ["number", "null"]},
          "lockages": {"type": "integer"},
          "commercial": {"type": "integer"},
          "barges": {"type": "integer"},
          "medianWait": {"type": ["number", "null"], "description": "Hours, over the recorded archive."},
          "recentMedianWait": {"type": ["number", "null"], "description": "Hours, over the trailing recent window when enough commercial tows are available."},
          "recentP90Wait": {"type": ["number", "null"], "description": "90th-percentile hours over the same recent commercial-tow sample as recentMedianWait; null below the minimum sample."},
          "first": {"type": ["string", "null"]},
          "last": {"type": ["string", "null"]},
          "status": {"oneOf": [{"$ref": "#/components/schemas/StatusObservation"}, {"type": "null"}]},
          "statusAsOf": {"type": ["string", "null"]},
          "statusStale": {"type": ["boolean", "null"], "description": "Verdict at build time only; re-evaluate age and source health when reading."},
          "alternateReport": {"$ref": "#/components/schemas/AlternateReport"},
          "riverGlance": {"$ref": "#/components/schemas/RiverGlance"},
          "separateDelay": {"$ref": "#/components/schemas/SeparateDelay"}
        },
        "additionalProperties": true
      },
      "LockIndex": {
        "type": "object",
        "required": ["generated", "days", "locks", "totals"],
        "properties": {
          "generated": {"type": "string", "format": "date-time", "description": "Site build time in UTC, not last Corps status time."},
          "days": {"type": "array", "items": {"type": "string", "format": "date"}, "description": "Dates covered by published daily traffic arrays."},
          "locks": {"type": "array", "items": {"$ref": "#/components/schemas/LockSummary"}},
          "totals": {"type": "object", "additionalProperties": true}
        },
        "additionalProperties": true
      },
      "CollectionHealth": {
        "type": "object",
        "required": ["generated", "healthy", "lastStatus"],
        "properties": {
          "generated": {"type": "string", "format": "date-time", "description": "Health report generation time, not a Corps status observation."},
          "healthy": {"type": "boolean", "description": "Collector verdict when the health report was written; also check lastStatus age at read time."},
          "lastStatus": {"type": ["string", "null"], "format": "date-time", "description": "Last successful Corps status collection in UTC."},
          "lastStatusAgeMin": {"type": ["number", "null"], "description": "Age when this health file was written; it grows stale without a refresh."},
          "statusSnapshots": {"type": "integer"},
          "alternateStatus": {"type": "object", "description": "Coverage of the separate, partial per-river archive; does not make healthy true.", "additionalProperties": true}
        },
        "additionalProperties": true
      },
      "LockArchive": {
        "type": "object",
        "required": ["id", "name", "riverName", "status", "lockageFields", "lockageRows"],
        "properties": {
          "id": {"type": "string"},
          "name": {"type": "string"},
          "riverName": {"type": "string"},
          "status": {"type": "array", "items": {"$ref": "#/components/schemas/StatusObservation"}},
          "alternateReport": {"$ref": "#/components/schemas/AlternateReport"},
          "riverGlance": {"$ref": "#/components/schemas/RiverGlance"},
          "separateDelay": {"$ref": "#/components/schemas/SeparateDelay"},
          "lockageFields": {"type": "array", "items": {"type": "string"}},
          "lockageRows": {"type": "array", "items": {"type": "array"}}
        },
        "additionalProperties": true
      },
      "QuietModel": {
        "type": "object",
        "required": ["lock_id", "generated", "observed_from", "observed_to", "sample_count", "live_conditions", "cells", "best_windows"],
        "properties": {
          "lock_id": {"type": "string"},
          "generated": {"type": "string", "format": "date-time", "description": "Site build time, not the time of a Corps status observation."},
          "observed_from": {"type": ["string", "null"], "format": "date"},
          "observed_to": {"type": ["string", "null"], "format": "date"},
          "sample_count": {"type": "integer"},
          "hours_reported_at": {"type": ["string", "null"], "description": "Last archived Corps operating-hours report timestamp."},
          "live_conditions": {"const": false},
          "cells": {"type": "array", "description": "Seven Monday-first arrays of 24 hour cells.",
                    "items": {"type": "array", "items": {"type": "object", "properties": {
                      "n": {"type": "integer"}, "median_hours": {"type": ["number", "null"]},
                      "p90_hours": {"type": ["number", "null"]},
                      "confidence": {"enum": ["none", "low", "medium", "high"]},
                      "quiet_candidate": {"type": "boolean"}}}}},
          "best_windows": {"type": "array", "description": "Up to three historically low-wait cells; not a departure recommendation.", "items": {"type": "object"}}
        },
        "additionalProperties": true
      }
    }
  }
}
