{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://recycle.moukaeritai.work/schema/9d633688-0a8f-4dc8-8f1a-66027bc0ac1a.schema.json",
  "title": "Geocoding cache schema for docs/latlng",
  "description": "Schema for geocoding cache JSON documents generated by scripts/geocode_batch.py.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "version",
    "generated_at",
    "source_file",
    "entries"
  ],
  "properties": {
    "version": {
      "type": "integer",
      "const": 1
    },
    "generated_at": {
      "$ref": "#/$defs/iso8601DateTime"
    },
    "source_file": {
      "type": "string",
      "pattern": "^docs/data/.+\\.json$"
    },
    "entries": {
      "type": "object",
      "description": "Map keyed by normalized address string.",
      "propertyNames": {
        "type": "string",
        "minLength": 1
      },
      "additionalProperties": {
        "$ref": "#/$defs/entry"
      }
    }
  },
  "$defs": {
    "iso8601DateTime": {
      "type": "string",
      "format": "date-time",
      "pattern": "(?:Z|[+-][0-9]{2}:[0-9]{2})$"
    },
    "entryBase": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "normalized_address",
        "raw_prefecture",
        "raw_address",
        "status",
        "updated_at"
      ],
      "properties": {
        "normalized_address": {
          "type": "string",
          "minLength": 1
        },
        "raw_prefecture": {
          "type": "string"
        },
        "raw_address": {
          "type": "string"
        },
        "status": {
          "type": "string",
          "enum": [
            "ok",
            "not_found",
            "error"
          ]
        },
        "updated_at": {
          "$ref": "#/$defs/iso8601DateTime"
        },
        "lat": {
          "type": "number",
          "minimum": -90,
          "maximum": 90
        },
        "lng": {
          "type": "number",
          "minimum": -180,
          "maximum": 180
        },
        "formatted_address": {
          "type": "string",
          "minLength": 1
        },
        "place_id": {
          "type": "string",
          "minLength": 1
        },
        "error_code": {
          "type": "string",
          "minLength": 1
        },
        "message": {
          "type": "string",
          "minLength": 1
        }
      }
    },
    "entry": {
      "allOf": [
        {
          "$ref": "#/$defs/entryBase"
        },
        {
          "if": {
            "properties": {
              "status": {
                "const": "ok"
              }
            }
          },
          "then": {
            "required": [
              "lat",
              "lng"
            ]
          }
        },
        {
          "if": {
            "properties": {
              "status": {
                "const": "error"
              }
            }
          },
          "then": {
            "required": [
              "error_code"
            ]
          }
        }
      ]
    }
  }
}
