{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/ringsaturn/xue/blob/main/docs/schemas/manifest.schema.json",
  "title": "RunManifest",
  "description": "A run's, a round's or a case's manifest.json, schema v5 (docs/zarr-profile.md, \"Manifest\"; docs/contribution/delivery.md): one entry per bundle naming its deliveries, every path relative to the manifest. The readers' own checks: that model and product name a registered dataset and forecastHours is the run's, that the core bundles are present on a live run, that variable names are unique, that every artifact path is unique in the manifest except a shared store's (a map store or segment whose final path component is bundles.zarr or bundles.<tier>.zarr, <tier> lowercase letters other than series) and columns' among them, that an entry or a tier carries its container (path, byteLength and crc32 together) or a zarr store or both, that a segmented store carries no path or crc32 of its own and its byteLength is its segments' sum, that a poster's metadataJson parses (as bundle-metadata.schema.json), and a bundle grid's rules beyond shape (bundle-metadata.schema.json).",
  "type": "object",
  "required": ["schemaVersion", "model", "product", "runTime", "forecastHours", "bundles"],
  "properties": {
    "schemaVersion": {"type": "integer", "const": 5},
    "model": {"description": "The dataset's manifest model, as bundle metadata names it (GFS, ECMWF, NOAA-MRMS, ...).", "type": "string", "minLength": 1},
    "product": {"type": "string", "minLength": 1},
    "runTime": {"$ref": "#/$defs/Timestamp"},
    "forecastHours": {"description": "The run's last lead, in whole hours rounded up.", "type": "integer", "minimum": 1, "maximum": 8760},
    "bundles": {"type": "array", "minItems": 1, "items": {"$ref": "#/$defs/Bundle"}},
    "columns": {"$ref": "#/$defs/ColumnStore"}
  },
  "$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"
    },
    "Crc32": {"description": "CRC-32 (IEEE) as eight lowercase hex digits: the ?v= an object is fetched under.", "type": "string", "pattern": "^[0-9a-f]{8}$"},
    "ByteLength": {"type": "integer", "minimum": 1},
    "Bundle": {
      "description": "One bundle of the run. A bundle that ships the container carries path, byteLength and crc32; one that ships only its store carries zarr.",
      "type": "object",
      "required": ["variable"],
      "properties": {
        "variable": {"description": "The bundle id: a name, not a registered number; a reader skips one it does not draw.", "type": "string", "pattern": "^[a-z][a-z0-9]*$"},
        "path": {"$ref": "#/$defs/ContainerPath"},
        "byteLength": {"$ref": "#/$defs/ByteLength"},
        "crc32": {"$ref": "#/$defs/Crc32"},
        "variants": {"description": "Reduced-resolution tiers, half first.", "type": "array", "minItems": 1, "items": {"$ref": "#/$defs/Variant"}},
        "poster": {"$ref": "#/$defs/Poster"},
        "zarr": {"$ref": "#/$defs/Zarr"},
        "series": {"$ref": "#/$defs/SeriesStore"},
        "grid": {"$ref": "#/$defs/Grid"}
      }
    },
    "ContainerPath": {
      "description": "A relative .xue path with no .. component.",
      "type": "string",
      "pattern": "^(?![/]|https?:)(?!(?:.*/)?\\.\\.(?:/|$)).*\\.xue$"
    },
    "Variant": {
      "description": "One reduced-resolution tier: its grid size, the bandwidth sustaining playback, and its container, its store or both.",
      "type": "object",
      "required": ["width", "height", "bandwidth"],
      "properties": {
        "width": {"type": "integer", "minimum": 1},
        "height": {"type": "integer", "minimum": 1},
        "bandwidth": {"description": "Bits per second to sustain 12 fps playback while downloading the whole tier.", "type": "integer", "minimum": 1},
        "path": {"$ref": "#/$defs/ContainerPath"},
        "byteLength": {"$ref": "#/$defs/ByteLength"},
        "crc32": {"$ref": "#/$defs/Crc32"},
        "zarr": {"$ref": "#/$defs/Zarr"}
      }
    },
    "Poster": {
      "description": "The first frame at reduced resolution, painted before the bundle arrives; metadataJson is the bundle's metadata on the poster grid, as a string.",
      "type": "object",
      "required": ["path", "width", "height", "byteLength", "crc32", "metadataJson"],
      "properties": {
        "path": {"type": "string", "pattern": "^(?![/]|https?:)(?!(?:.*/)?\\.\\.(?:/|$)).*\\.poster\\.bin$"},
        "width": {"type": "integer", "minimum": 1},
        "height": {"type": "integer", "minimum": 1},
        "byteLength": {"$ref": "#/$defs/ByteLength"},
        "crc32": {"$ref": "#/$defs/Crc32"},
        "metadataJson": {"type": "string", "minLength": 1}
      }
    },
    "Zarr": {
      "description": "A bundle's or a tier's map store: one store, or a rolling window's segments (docs/zarr-profile.md, \"Segmented stores\").",
      "anyOf": [{"$ref": "#/$defs/MapStore"}, {"$ref": "#/$defs/SegmentedStore"}]
    },
    "MapStore": {
      "description": "A map store: the store's root directory, the bytes this bundle reads in it, and the CRC-32 of its group document.",
      "type": "object",
      "required": ["path", "byteLength", "crc32"],
      "properties": {
        "path": {"type": "string", "pattern": "^(?![/]|https?:)(?!(?:.*/)?\\.\\.(?:/|$)).*\\.zarr$"},
        "byteLength": {"$ref": "#/$defs/ByteLength"},
        "crc32": {"$ref": "#/$defs/Crc32"}
      }
    },
    "SegmentedStore": {
      "description": "A map store cut along time: the segments in ascending time order, and byteLength their sum.",
      "type": "object",
      "required": ["byteLength", "segments"],
      "properties": {
        "byteLength": {"$ref": "#/$defs/ByteLength"},
        "segments": {"type": "array", "minItems": 1, "items": {"$ref": "#/$defs/Segment"}}
      }
    },
    "Segment": {
      "description": "One segment store; its path may climb out of the manifest's directory with at most two leading .. components, and nowhere else.",
      "type": "object",
      "required": ["path", "byteLength", "crc32"],
      "properties": {
        "path": {"type": "string", "pattern": "^(?:\\.\\./){0,2}(?![/]|https?:)(?!(?:.*/)?\\.\\.(?:/|$))(?:[^/]+/)*[^/]+\\.zarr$"},
        "byteLength": {"$ref": "#/$defs/ByteLength"},
        "crc32": {"$ref": "#/$defs/Crc32"}
      }
    },
    "SeriesStore": {
      "description": "The bundle's series store (docs/zarr-profile.md, \"Series store\"): full resolution only, never shared, never segmented.",
      "type": "object",
      "required": ["path", "byteLength", "crc32"],
      "properties": {
        "path": {"type": "string", "pattern": "^(?![/]|https?:)(?!(?:.*/)?\\.\\.(?:/|$)).*\\.series\\.zarr$"},
        "byteLength": {"$ref": "#/$defs/ByteLength"},
        "crc32": {"$ref": "#/$defs/Crc32"}
      }
    },
    "ColumnStore": {
      "description": "The run's column store (docs/zarr-profile.md, \"Column store\"): the store's root directory, the sum of every object in it, and the CRC-32 of its group document. Absent on a run without one, a round and a case.",
      "type": "object",
      "required": ["path", "byteLength", "crc32"],
      "properties": {
        "path": {"type": "string", "pattern": "^(?![/]|https?:)(?!(?:.*/)?\\.\\.(?:/|$))(?:.*/)?columns\\.zarr$"},
        "byteLength": {"$ref": "#/$defs/ByteLength"},
        "crc32": {"$ref": "#/$defs/Crc32"}
      }
    },
    "Grid": {
      "description": "The bundle's full grid, as its metadata's grid block says it: written on entries whose readers locate a cell without opening the store. Regular or projected, by the rule of bundle-metadata.schema.json#/$defs/Grid.",
      "type": "object",
      "required": ["width", "height", "wrapLongitude"],
      "anyOf": [
        {
          "type": "object",
          "required": ["firstLongitude", "firstLatitude", "longitudeStep", "latitudeStep"],
          "properties": {"projection": {"type": "null"}}
        },
        {
          "type": "object",
          "required": ["projection"],
          "properties": {
            "firstLongitude": {"type": "null"},
            "firstLatitude": {"type": "null"},
            "longitudeStep": {"type": "null"},
            "latitudeStep": {"type": "null"},
            "gaussian": {"type": "null"},
            "wrapLongitude": {"const": false}
          }
        }
      ],
      "properties": {
        "width": {"type": "integer", "minimum": 1},
        "height": {"type": "integer", "minimum": 1},
        "firstLongitude": {"type": "number"},
        "firstLatitude": {"type": "number"},
        "longitudeStep": {"type": "number"},
        "latitudeStep": {"type": "number"},
        "wrapLongitude": {"type": "boolean"},
        "gaussian": {"$ref": "bundle-metadata.schema.json#/$defs/Gaussian"},
        "projection": {"$ref": "bundle-metadata.schema.json#/$defs/Projection"}
      }
    }
  }
}
