{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "schema_version": {
      "const": "1.0"
    },
    "as_of": {
      "type": "string",
      "format": "date-time"
    },
    "currency": {
      "const": "EUR"
    },
    "availability_note": {
      "const": "Listed on LKC. Confirm current terms and availability with the provider."
    },
    "offers": {
      "type": "array",
      "maxItems": 5,
      "items": {
        "$ref": "#/$defs/offer"
      }
    }
  },
  "required": [
    "schema_version",
    "as_of",
    "currency",
    "availability_note",
    "offers"
  ],
  "additionalProperties": false,
  "$defs": {
    "offer": {
      "type": "object",
      "properties": {
        "rank": {
          "type": "integer",
          "minimum": 1,
          "maximum": 5
        },
        "title": {
          "type": "string",
          "minLength": 1,
          "maxLength": 180
        },
        "vehicle": {
          "$ref": "#/$defs/vehicle"
        },
        "model_profiles": {
          "$ref": "#/$defs/model_profiles"
        },
        "vehicle_image": {
          "type": "null"
        },
        "listed_at": {
          "anyOf": [
            {
              "type": "string",
              "format": "date-time"
            },
            {
              "type": "null"
            }
          ]
        },
        "editorial_tip": {
          "type": "boolean"
        },
        "availability": {
          "const": "indexed_only"
        },
        "contract": {
          "type": "object",
          "properties": {
            "audience": {
              "enum": [
                "private",
                "business"
              ]
            },
            "term_months": {
              "type": "integer",
              "minimum": 1,
              "maximum": 120
            },
            "annual_km": {
              "type": "integer",
              "minimum": 0,
              "maximum": 100000
            },
            "delivery_days": {
              "anyOf": [
                {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 10000
                },
                {
                  "type": "null"
                }
              ]
            },
            "product_type": {
              "const": "leasing"
            },
            "available_immediately": {
              "anyOf": [
                {
                  "type": "boolean"
                },
                {
                  "type": "null"
                }
              ]
            }
          },
          "required": [
            "audience",
            "term_months",
            "annual_km",
            "delivery_days",
            "product_type",
            "available_immediately"
          ],
          "additionalProperties": false
        },
        "pricing": {
          "$ref": "#/$defs/pricing"
        },
        "leasing_score": {
          "$ref": "#/$defs/leasing_score"
        },
        "operating_score": {
          "anyOf": [
            {
              "$ref": "#/$defs/operating_score"
            },
            {
              "type": "null"
            }
          ]
        },
        "url": {
          "type": "string",
          "pattern": "^https://www\\.leasingkostencheck\\.de/(zum-anbieter/[0-9a-f]{32}-l/|mcp-go/\\?t=[A-Za-z0-9_-]{1,768}\\.[a-f0-9]{64}(&rid=[a-f0-9]{32})?)$"
        },
        "link_label": {
          "const": "Zum Angebot"
        },
        "data_gaps": {
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^[A-Za-z0-9_.]{1,70}$"
          },
          "uniqueItems": true,
          "maxItems": 40
        }
      },
      "required": [
        "rank",
        "title",
        "vehicle",
        "model_profiles",
        "vehicle_image",
        "listed_at",
        "editorial_tip",
        "availability",
        "contract",
        "pricing",
        "leasing_score",
        "operating_score",
        "url",
        "link_label",
        "data_gaps"
      ],
      "additionalProperties": false,
      "allOf": [
        {
          "if": {
            "properties": {
              "vehicle": {
                "properties": {
                  "fuel_type": {
                    "enum": [
                      "electric",
                      "plug_in_hybrid"
                    ]
                  }
                }
              }
            }
          },
          "else": {
            "properties": {
              "model_profiles": {
                "not": {
                  "anyOf": [
                    {
                      "required": [
                        "range_class"
                      ]
                    },
                    {
                      "required": [
                        "charging_class"
                      ]
                    }
                  ]
                }
              }
            }
          }
        }
      ]
    },
    "vehicle": {
      "type": "object",
      "properties": {
        "brand": {
          "type": "string",
          "minLength": 1,
          "maxLength": 64
        },
        "model": {
          "type": "string",
          "minLength": 1,
          "maxLength": 64
        },
        "variant": {
          "anyOf": [
            {
              "type": "string",
              "minLength": 1,
              "maxLength": 160
            },
            {
              "type": "null"
            }
          ]
        },
        "body_type": {
          "anyOf": [
            {
              "type": "string",
              "minLength": 1,
              "maxLength": 48
            },
            {
              "type": "null"
            }
          ]
        },
        "condition": {
          "anyOf": [
            {
              "enum": [
                "new",
                "used"
              ]
            },
            {
              "type": "null"
            }
          ]
        },
        "fuel_type": {
          "anyOf": [
            {
              "enum": [
                "electric",
                "plug_in_hybrid",
                "petrol",
                "diesel",
                "hybrid"
              ]
            },
            {
              "type": "null"
            }
          ]
        },
        "combustion_fuel": {
          "anyOf": [
            {
              "enum": [
                "petrol",
                "diesel"
              ]
            },
            {
              "type": "null"
            }
          ]
        },
        "wheel_drive": {
          "anyOf": [
            {
              "enum": [
                "front",
                "rear",
                "all_wheel",
                "two_wheel"
              ]
            },
            {
              "type": "null"
            }
          ]
        },
        "transmission": {
          "anyOf": [
            {
              "enum": [
                "automatic",
                "manual"
              ]
            },
            {
              "type": "null"
            }
          ]
        },
        "power_kw": {
          "anyOf": [
            {
              "type": "integer",
              "minimum": 1,
              "maximum": 1500
            },
            {
              "type": "null"
            }
          ]
        },
        "power_ps": {
          "anyOf": [
            {
              "type": "integer",
              "minimum": 1,
              "maximum": 2000
            },
            {
              "type": "null"
            }
          ]
        },
        "seats": {
          "anyOf": [
            {
              "type": "integer",
              "minimum": 1,
              "maximum": 30
            },
            {
              "type": "null"
            }
          ]
        },
        "odometer_km": {
          "anyOf": [
            {
              "type": "integer",
              "minimum": 0,
              "maximum": 1000000
            },
            {
              "type": "null"
            }
          ]
        },
        "first_registration": {
          "anyOf": [
            {
              "type": "string",
              "pattern": "^[0-9]{4}-(0[1-9]|1[0-2])(?:-[0-3][0-9])?$"
            },
            {
              "type": "null"
            }
          ]
        },
        "color": {
          "anyOf": [
            {
              "type": "string",
              "minLength": 1,
              "maxLength": 32
            },
            {
              "type": "null"
            }
          ]
        },
        "combined_fuel_l_per_100km": {
          "anyOf": [
            {
              "type": "number",
              "minimum": 0,
              "maximum": 100
            },
            {
              "type": "null"
            }
          ]
        },
        "combined_co2_g_per_km": {
          "anyOf": [
            {
              "type": "integer",
              "minimum": 0,
              "maximum": 1500
            },
            {
              "type": "null"
            }
          ]
        },
        "co2_class": {
          "anyOf": [
            {
              "type": "string",
              "pattern": "^[A-G]$"
            },
            {
              "type": "null"
            }
          ]
        },
        "listing_reported_features": {
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]{0,47}$"
          },
          "uniqueItems": true,
          "maxItems": 30
        }
      },
      "required": [
        "brand",
        "model",
        "variant",
        "body_type",
        "condition",
        "fuel_type",
        "combustion_fuel",
        "wheel_drive",
        "transmission",
        "power_kw",
        "power_ps",
        "seats",
        "odometer_km",
        "first_registration",
        "color",
        "combined_fuel_l_per_100km",
        "combined_co2_g_per_km",
        "co2_class",
        "listing_reported_features"
      ],
      "additionalProperties": false
    },
    "model_profiles": {
      "type": "object",
      "properties": {
        "family": {
          "anyOf": [
            {
              "enum": [
                "single",
                "couple",
                "family",
                "large_family",
                "not_tagged"
              ]
            },
            {
              "type": "null"
            }
          ]
        },
        "distance_profile": {
          "enum": [
            "short",
            "medium",
            "long",
            "touring"
          ]
        },
        "city_suitability": {
          "enum": [
            "ideal",
            "suitable",
            "limited",
            "unsuitable"
          ]
        },
        "business_use": {
          "enum": [
            "sales",
            "city_business",
            "executive",
            "commercial_use"
          ]
        },
        "comfort_class": {
          "enum": [
            "basic",
            "comfort",
            "premium"
          ]
        },
        "market_position": {
          "enum": [
            "mainstream",
            "upper_mainstream",
            "premium",
            "luxury"
          ]
        },
        "subsegment": {
          "type": "string",
          "minLength": 1,
          "maxLength": 48
        },
        "range_class": {
          "enum": [
            "urban",
            "everyday",
            "touring",
            "long_distance"
          ]
        },
        "charging_class": {
          "enum": [
            "slow",
            "standard",
            "fast",
            "ultrafast"
          ]
        }
      },
      "required": [],
      "additionalProperties": false
    },
    "pricing": {
      "type": "object",
      "properties": {
        "tax_basis": {
          "enum": [
            "gross",
            "net"
          ]
        },
        "monthly_rate_cents": {
          "type": "integer",
          "minimum": 1,
          "maximum": 10000000
        },
        "gross_monthly_rate_cents": {
          "anyOf": [
            {
              "type": "integer",
              "minimum": 0,
              "maximum": 100000000
            },
            {
              "type": "null"
            }
          ]
        },
        "net_monthly_rate_cents": {
          "anyOf": [
            {
              "type": "integer",
              "minimum": 0,
              "maximum": 100000000
            },
            {
              "type": "null"
            }
          ]
        },
        "down_payment_cents": {
          "anyOf": [
            {
              "type": "integer",
              "minimum": 0,
              "maximum": 100000000
            },
            {
              "type": "null"
            }
          ]
        },
        "setup_fee_cents": {
          "anyOf": [
            {
              "type": "integer",
              "minimum": 0,
              "maximum": 100000000
            },
            {
              "type": "null"
            }
          ]
        },
        "setup_fee_tax_basis": {
          "anyOf": [
            {
              "enum": [
                "gross",
                "net"
              ]
            },
            {
              "type": "null"
            }
          ]
        },
        "effective_monthly_rate_cents": {
          "anyOf": [
            {
              "type": "integer",
              "minimum": 0,
              "maximum": 100000000
            },
            {
              "type": "null"
            }
          ]
        },
        "leasing_factor": {
          "anyOf": [
            {
              "type": "number",
              "minimum": 0,
              "maximum": 100
            },
            {
              "type": "null"
            }
          ]
        },
        "effective_leasing_factor": {
          "anyOf": [
            {
              "type": "number",
              "minimum": 0,
              "maximum": 100
            },
            {
              "type": "null"
            }
          ]
        },
        "leasing_factor_tax_basis": {
          "enum": [
            "gross",
            "net"
          ]
        },
        "electric_grant": {
          "enum": [
            "not_applicable",
            "not_included",
            "included_in_advertised_rate",
            "unknown"
          ]
        }
      },
      "required": [
        "tax_basis",
        "monthly_rate_cents",
        "gross_monthly_rate_cents",
        "net_monthly_rate_cents",
        "down_payment_cents",
        "setup_fee_cents",
        "setup_fee_tax_basis",
        "effective_monthly_rate_cents",
        "leasing_factor",
        "effective_leasing_factor",
        "electric_grant"
      ],
      "additionalProperties": false
    },
    "leasing_score": {
      "type": "object",
      "properties": {
        "score": {
          "type": "number",
          "minimum": 0,
          "maximum": 100
        },
        "scale_max": {
          "const": 100
        },
        "components": {
          "type": "object",
          "properties": {
            "rate_and_setup_vs_list_price": {
              "type": "number",
              "minimum": 0,
              "maximum": 100
            },
            "contract_terms": {
              "type": "number",
              "minimum": 0,
              "maximum": 100
            },
            "down_payment": {
              "type": "number",
              "minimum": 0,
              "maximum": 100
            },
            "setup_fee": {
              "type": "number",
              "minimum": 0,
              "maximum": 100
            },
            "effective_rate_uplift": {
              "type": "number",
              "minimum": 0,
              "maximum": 100
            }
          },
          "required": [],
          "additionalProperties": false
        }
      },
      "required": [
        "score",
        "scale_max",
        "components"
      ],
      "additionalProperties": false
    },
    "operating_score": {
      "type": "object",
      "properties": {
        "score": {
          "type": "number",
          "minimum": 0,
          "maximum": 100
        },
        "scale_max": {
          "const": 100
        },
        "component_scores": {
          "type": "object",
          "properties": {
            "insurance": {
              "type": "number",
              "minimum": 0,
              "maximum": 100
            },
            "tax": {
              "type": "number",
              "minimum": 0,
              "maximum": 100
            },
            "energy": {
              "type": "number",
              "minimum": 0,
              "maximum": 100
            },
            "maintenance": {
              "type": "number",
              "minimum": 0,
              "maximum": 100
            }
          },
          "required": [],
          "additionalProperties": false
        }
      },
      "required": [
        "score",
        "scale_max",
        "component_scores"
      ],
      "additionalProperties": false
    }
  }
}
