{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://car-general.local/schemas/tire-model.schema.json",
  "title": "タイヤ銘柄とサイズのカタログ",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "$schema",
    "schema_version",
    "id",
    "manufacturer",
    "model",
    "season",
    "status",
    "checked_on",
    "sources",
    "sizes",
    "notes"
  ],
  "properties": {
    "$schema": {
      "const": "../../tire-model.schema.json"
    },
    "schema_version": {
      "const": "1.0"
    },
    "id": {
      "type": "string",
      "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
    },
    "manufacturer": {
      "type": "string",
      "minLength": 1
    },
    "model": {
      "type": "string",
      "minLength": 1
    },
    "season": {
      "enum": [
        "summer",
        "winter",
        "all_season",
        "unknown"
      ]
    },
    "status": {
      "enum": [
        "official_listed",
        "unknown"
      ]
    },
    "checked_on": {
      "type": "string",
      "format": "date"
    },
    "sources": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "string",
        "format": "uri",
        "pattern": "^https?://"
      }
    },
    "notes": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "sizes": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/size"
      }
    }
  },
  "$defs": {
    "size": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "designation",
        "width_mm",
        "aspect_ratio_pct",
        "rim_diameter_in",
        "load_speed",
        "overall_diameter_mm",
        "section_width_mm",
        "standard_rim_width_in",
        "permitted_rim_width_in",
        "product_code",
        "raw",
        "source_url"
      ],
      "properties": {
        "designation": {
          "type": "string",
          "pattern": "^((P|LT|HL)?[0-9]{3}/[0-9]{2}(ZR|RF|R)[0-9]{2}|[0-9]{2}X[0-9]{1,2}\\.[0-9]{2}R[0-9]{2}|[0-9]{3}R[0-9]{2}C?|[0-9]{1,2}\\.[0-9]{2}R[0-9]{2})$"
        },
        "width_mm": {
          "type": "number",
          "minimum": 100,
          "maximum": 400
        },
        "aspect_ratio_pct": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": 20,
          "maximum": 100
        },
        "rim_diameter_in": {
          "type": "integer",
          "minimum": 10,
          "maximum": 30
        },
        "load_speed": {
          "type": [
            "string",
            "null"
          ]
        },
        "overall_diameter_mm": {
          "type": [
            "number",
            "null"
          ],
          "exclusiveMinimum": 0
        },
        "section_width_mm": {
          "type": [
            "number",
            "null"
          ],
          "exclusiveMinimum": 0
        },
        "standard_rim_width_in": {
          "type": [
            "number",
            "null"
          ],
          "exclusiveMinimum": 0
        },
        "permitted_rim_width_in": {
          "oneOf": [
            {
              "type": "null"
            },
            {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "minimum",
                "maximum"
              ],
              "properties": {
                "minimum": {
                  "type": "number",
                  "exclusiveMinimum": 0
                },
                "maximum": {
                  "type": "number",
                  "exclusiveMinimum": 0
                }
              }
            }
          ]
        },
        "product_code": {
          "type": [
            "string",
            "null"
          ]
        },
        "raw": {
          "type": "string",
          "minLength": 1
        },
        "source_url": {
          "type": "string",
          "format": "uri",
          "pattern": "^https?://"
        },
        "manufacturing_country": {
          "description": "製造国が対象サイズ・製造時期・個体等の範囲まで一次資料で確認できる場合のみ記録。未確認は省略またはnull。",
          "oneOf": [
            {
              "type": "null"
            },
            {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "code",
                "scope",
                "source_url"
              ],
              "properties": {
                "code": {
                  "type": "string",
                  "pattern": "^[A-Z]{2}$"
                },
                "scope": {
                  "type": "string",
                  "minLength": 1
                },
                "source_url": {
                  "type": "string",
                  "format": "uri",
                  "pattern": "^https?://"
                }
              }
            }
          ]
        },
        "availability_note": {
          "type": "string",
          "minLength": 1,
          "description": "情報源に記載されたサイズ別注記。供給状況は情報源掲載時点のもので、現在の在庫を保証しない。"
        }
      }
    }
  }
}
