{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://tomori-map.com/schema/diary-public-day.v2.json",
  "title": "TOMORI station diary: one station, one day",
  "type": "object",
  "properties": {
    "schema_version": {
      "type": "integer",
      "const": 2
    },
    "subject": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "const": "station"
        },
        "id": {
          "type": "string"
        }
      },
      "required": ["type", "id"]
    },
    "date": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
    },
    "model_version": {
      "type": "string"
    },
    "content_hash": {
      "type": "string",
      "description": "SHA-256 of the stored document (canonical JSON). Matches one Merkle leaf."
    },
    "fact": {
      "type": ["object", "null"],
      "description": "Transcribed JMA AMeDAS observation for the day. Never an estimate.",
      "properties": {
        "provenance": {
          "type": "string",
          "const": "sensor"
        },
        "kind": {
          "type": "string",
          "const": "fact"
        },
        "origin": {
          "type": "string"
        },
        "temp_c_hourly": {
          "type": "array",
          "items": {
            "type": ["number", "null"]
          }
        },
        "sun1h_hourly": {
          "type": "array",
          "items": {
            "type": ["number", "null"]
          }
        },
        "humidity_hourly": {
          "type": "array",
          "items": {
            "type": ["number", "null"]
          }
        },
        "snow_cm_hourly": {
          "type": "array",
          "items": {
            "type": ["number", "null"]
          }
        },
        "wind_ms_hourly": {
          "type": "array",
          "items": {
            "type": ["number", "null"]
          }
        },
        "wind_dir_hourly": {
          "type": "array",
          "items": {
            "type": ["number", "null"]
          }
        },
        "pressure_hpa_hourly": {
          "type": "array",
          "items": {
            "type": ["number", "null"]
          }
        },
        "t_max_c": {
          "type": ["number", "null"]
        },
        "t_min_c": {
          "type": ["number", "null"]
        },
        "quality": {
          "type": "object",
          "properties": {
            "missing_hours": {
              "type": "integer"
            }
          },
          "required": ["missing_hours"]
        },
        "source_url": {
          "type": "string"
        },
        "as_of": {
          "type": "string"
        }
      },
      "required": ["provenance", "kind", "temp_c_hourly", "source_url", "as_of"]
    },
    "scoring": {
      "type": ["object", "null"],
      "description": "Differences between the previous day expectation and what was observed. Differences only, never a verdict."
    },
    "attribution": {
      "type": ["object", "null"]
    },
    "anomaly": {
      "type": ["object", "null"]
    },
    "anchor": {
      "type": ["object", "null"],
      "properties": {
        "date": {
          "type": "string",
          "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
        },
        "root": {
          "type": "string"
        },
        "leaf_count": {
          "type": "integer"
        },
        "model_version": {
          "type": "string"
        },
        "leaves": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "path": {
                "type": "string"
              },
              "content_hash": {
                "type": "string"
              }
            },
            "required": ["path", "content_hash"],
            "additionalProperties": false
          }
        }
      },
      "required": ["date", "root", "leaf_count", "model_version", "leaves"]
    },
    "method_uri": {
      "type": "string",
      "description": "Methodology document (REQ-37-01)."
    },
    "license": {
      "type": "string",
      "description": "Usage licence of the published record (CC BY 4.0)."
    },
    "schema_uri": {
      "type": "string",
      "description": "Location of this schema document."
    },
    "source": {
      "type": "string",
      "const": "measured",
      "description": "The day record is a transcription of the JMA AMeDAS observation (added 2026-10-08, additive). The scoring section is modelled."
    },
    "provenance": {
      "type": "string",
      "const": "tomori_diary_station"
    },
    "as_of": {
      "type": "string",
      "description": "When the observation was retrieved (ISO 8601). Empty when the day has no rows."
    },
    "identifiers": {
      "type": "object",
      "description": "External identifiers. jis_city_code is the municipality that uses this station as its representative station (not where the station stands), or null. h3_res8 is the H3 resolution 8 cell of the published station coordinates.",
      "properties": {
        "amedas_station_id": {
          "type": "string"
        },
        "jis_city_code": {
          "type": ["string", "null"]
        },
        "h3_res8": {
          "type": ["string", "null"]
        }
      },
      "required": ["amedas_station_id", "jis_city_code", "h3_res8"]
    }
  },
  "required": [
    "schema_version",
    "subject",
    "date",
    "model_version",
    "content_hash",
    "method_uri",
    "license",
    "schema_uri"
  ],
  "additionalProperties": false
}
