{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/ringsaturn/xue/blob/main/docs/schemas/airport-index.schema.json",
  "title": "AirportIndex",
  "description": "airport/<YYYY>/<MM>/<DD>/airport.<round>/index.json (docs/airport.md section 4). The history file's name, the rows' order and uniqueness and their byte spans are the readers' own checks.",
  "type": "object",
  "required": ["schemaVersion", "issued", "generated", "history", "stations", "sources"],
  "properties": {
    "schemaVersion": {"type": "integer", "const": 1},
    "issued": {
      "description": "The round: a UTC minute that is a multiple of ten.",
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d0:00Z$",
      "format": "date-time"
    },
    "generated": {"$ref": "#/$defs/Timestamp"},
    "history": {"$ref": "#/$defs/CrcFile"},
    "columns": {
      "description": "The stations rows' columns by name. A reader finds a column by its name here; an index written before the field has the same layout and is read by position.",
      "type": "array",
      "minItems": 16,
      "maxItems": 16,
      "prefixItems": [
        {"const": "icao"},
        {"const": "lat"},
        {"const": "lon"},
        {"const": "elev"},
        {"const": "obsTime"},
        {"const": "t"},
        {"const": "td"},
        {"const": "wd"},
        {"const": "ws"},
        {"const": "gust"},
        {"const": "vis"},
        {"const": "qnh"},
        {"const": "category"},
        {"const": "tafPresent"},
        {"const": "offset"},
        {"const": "length"}
      ]
    },
    "stations": {"type": "array", "items": {"$ref": "#/$defs/AirportStationRow"}},
    "sources": {"type": "array", "items": {"$ref": "#/$defs/AirportSource"}}
  },
  "$defs": {
    "Timestamp": {
      "description": "ISO 8601 UTC, to the second, with a Z suffix.",
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$",
      "format": "date-time"
    },
    "CrcFile": {
      "description": "The file beside the index: its name, length and zlib CRC32.",
      "type": "object",
      "required": ["path", "byteLength", "crc32"],
      "properties": {
        "path": {"type": "string", "minLength": 1},
        "byteLength": {"type": "integer", "minimum": 0},
        "crc32": {"type": "string", "pattern": "^[0-9a-f]{8}$"}
      }
    },
    "AirportStationRow": {
      "description": "[icao, lat, lon, elev, obsTime, t, td, wd, ws, gust, vis, qnh, category, tafPresent, offset, length]: the station's newest observation (degrees C, degrees true, m/s, metres, hPa) and the byte span of its line in history.jsonl.",
      "type": "array",
      "minItems": 16,
      "prefixItems": [
        {"type": "string", "pattern": "^[A-Z0-9]{2,4}$"},
        {"type": "number", "minimum": -90, "maximum": 90},
        {"type": "number", "minimum": -180, "maximum": 180},
        {"type": ["number", "null"], "minimum": -500, "maximum": 9000},
        {"$ref": "#/$defs/Timestamp"},
        {"type": ["number", "null"], "minimum": -100, "maximum": 70},
        {"type": ["number", "null"], "minimum": -100, "maximum": 70},
        {"type": ["integer", "null"], "minimum": 0, "maximum": 360},
        {"type": ["number", "null"], "minimum": 0, "maximum": 150},
        {"type": ["number", "null"], "minimum": 0, "maximum": 150},
        {"type": ["integer", "null"], "minimum": 0},
        {"type": ["number", "null"], "minimum": 800, "maximum": 1100},
        {"enum": ["VFR", "MVFR", "IFR", "LIFR", null]},
        {"enum": [0, 1]},
        {"type": "integer", "minimum": 0},
        {"type": "integer", "minimum": 1}
      ]
    },
    "AirportSource": {
      "description": "One source's outcome (docs/airport.md section 6). That ok false carries error, and that ids are unique, are the readers' own checks.",
      "type": "object",
      "required": ["id", "ok"],
      "properties": {
        "id": {"type": "string", "pattern": "^[a-z][a-z0-9-]*$"},
        "ok": {"type": "boolean"},
        "error": {"type": "string"},
        "fetched": {"$ref": "#/$defs/Timestamp"},
        "url": {"type": "string"},
        "bytes": {"type": "integer", "minimum": 0},
        "reports": {"type": "integer", "minimum": 0},
        "cached": {"type": "boolean"},
        "modified": {"description": "The station table's Last-Modified, verbatim, when a copy on disk was kept.", "type": ["string", "null"]}
      }
    }
  }
}
