{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://tapinomahub.com/schemas/recycler-market-data-v1.schema.json",
  "title": "tapinomahub Marktdatenimport fuer Demontagebetriebe und Verwerter v1",
  "description": "Maschinenlesbarer Vertrag fuer Fahrzeug-, Teile-, Listing- und Verkaufsdaten.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "export",
    "vehicles",
    "parts",
    "listings",
    "listing_events",
    "listing_metrics",
    "sales",
    "tombstones"
  ],
  "properties": {
    "schema_version": {
      "const": "1.0.0"
    },
    "export": {
      "$ref": "#/$defs/export"
    },
    "vehicles": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/vehicle"
      }
    },
    "parts": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/part"
      }
    },
    "listings": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/listing"
      }
    },
    "listing_events": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/listingEvent"
      }
    },
    "listing_metrics": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/listingMetric"
      }
    },
    "sales": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/sale"
      }
    },
    "tombstones": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/tombstone"
      }
    }
  },
  "$defs": {
    "sourceId": {
      "type": "string",
      "minLength": 1,
      "maxLength": 200
    },
    "optionalText": {
      "type": "string",
      "minLength": 1,
      "maxLength": 2000
    },
    "nullableDateTime": {
      "oneOf": [
        {
          "type": "string",
          "format": "date-time"
        },
        {
          "type": "null"
        }
      ]
    },
    "countryCode": {
      "type": "string",
      "pattern": "^[A-Z]{2}$"
    },
    "currencyCode": {
      "type": "string",
      "pattern": "^[A-Z]{3}$"
    },
    "money": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "amount_minor",
        "currency",
        "price_basis"
      ],
      "properties": {
        "amount_minor": {
          "type": "integer",
          "minimum": 0
        },
        "currency": {
          "$ref": "#/$defs/currencyCode"
        },
        "price_basis": {
          "enum": [
            "gross",
            "net",
            "unknown"
          ]
        },
        "tax_treatment": {
          "enum": [
            "standard_vat",
            "margin_scheme",
            "tax_exempt",
            "reverse_charge",
            "unknown"
          ]
        }
      }
    },
    "nullableMoney": {
      "oneOf": [
        {
          "$ref": "#/$defs/money"
        },
        {
          "type": "null"
        }
      ]
    },
    "economicEntry": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "type",
        "direction",
        "amount",
        "valuation_method"
      ],
      "properties": {
        "type": {
          "enum": [
            "vehicle_acquisition",
            "inbound_transport",
            "dismantling",
            "testing",
            "refurbishment",
            "storage",
            "packaging",
            "outbound_shipping",
            "marketplace_fee",
            "payment_fee",
            "return",
            "disposal",
            "scrap_revenue",
            "core_revenue",
            "other"
          ]
        },
        "direction": {
          "enum": [
            "cost",
            "revenue"
          ]
        },
        "amount": {
          "$ref": "#/$defs/money"
        },
        "valuation_method": {
          "enum": [
            "actual",
            "allocated",
            "estimated",
            "unknown"
          ]
        },
        "occurred_at": {
          "$ref": "#/$defs/nullableDateTime"
        },
        "note": {
          "$ref": "#/$defs/optionalText"
        }
      }
    },
    "completeness": {
      "enum": [
        "complete",
        "partial",
        "unknown"
      ]
    },
    "export": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "export_id",
        "mode",
        "exported_at",
        "source",
        "coverage"
      ],
      "properties": {
        "export_id": {
          "$ref": "#/$defs/sourceId"
        },
        "mode": {
          "enum": [
            "full_snapshot",
            "delta"
          ]
        },
        "exported_at": {
          "type": "string",
          "format": "date-time"
        },
        "period_from": {
          "type": "string",
          "format": "date-time"
        },
        "period_to": {
          "type": "string",
          "format": "date-time"
        },
        "snapshot_at": {
          "type": "string",
          "format": "date-time"
        },
        "sequence": {
          "type": "integer",
          "minimum": 0
        },
        "source": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "partner_id",
            "source_system"
          ],
          "properties": {
            "partner_id": {
              "$ref": "#/$defs/sourceId"
            },
            "source_system": {
              "type": "string",
              "minLength": 1,
              "maxLength": 200
            },
            "source_system_version": {
              "type": "string",
              "minLength": 1,
              "maxLength": 100
            }
          }
        },
        "coverage": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "vehicle_inventory",
            "part_inventory",
            "listings",
            "listing_history",
            "sales",
            "returns"
          ],
          "properties": {
            "vehicle_inventory": {
              "$ref": "#/$defs/completeness"
            },
            "part_inventory": {
              "$ref": "#/$defs/completeness"
            },
            "listings": {
              "$ref": "#/$defs/completeness"
            },
            "listing_history": {
              "$ref": "#/$defs/completeness"
            },
            "sales": {
              "$ref": "#/$defs/completeness"
            },
            "returns": {
              "$ref": "#/$defs/completeness"
            },
            "history_available_from": {
              "$ref": "#/$defs/nullableDateTime"
            },
            "note": {
              "$ref": "#/$defs/optionalText"
            }
          },
          "allOf": [
            {
              "if": {
                "anyOf": [
                  {
                    "required": [
                      "listing_history"
                    ],
                    "properties": {
                      "listing_history": {
                        "const": "complete"
                      }
                    }
                  },
                  {
                    "required": [
                      "returns"
                    ],
                    "properties": {
                      "returns": {
                        "const": "complete"
                      }
                    }
                  }
                ]
              },
              "then": {
                "required": [
                  "history_available_from"
                ],
                "properties": {
                  "history_available_from": {
                    "type": "string",
                    "format": "date-time"
                  }
                }
              }
            }
          ]
        },
        "scope": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "source_location_ids",
            "source_channel_ids",
            "entity_types"
          ],
          "properties": {
            "source_location_ids": {
              "type": "array",
              "minItems": 1,
              "uniqueItems": true,
              "items": {
                "$ref": "#/$defs/sourceId"
              }
            },
            "source_channel_ids": {
              "type": "array",
              "minItems": 1,
              "uniqueItems": true,
              "items": {
                "$ref": "#/$defs/sourceId"
              }
            },
            "entity_types": {
              "type": "array",
              "minItems": 1,
              "uniqueItems": true,
              "items": {
                "enum": [
                  "vehicles",
                  "parts",
                  "listings",
                  "listing_events",
                  "listing_metrics",
                  "sales",
                  "tombstones"
                ]
              }
            }
          }
        },
        "record_counts": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "vehicles",
            "parts",
            "listings",
            "listing_events",
            "listing_metrics",
            "sales",
            "sale_events",
            "tombstones"
          ],
          "properties": {
            "vehicles": {
              "type": "integer",
              "minimum": 0
            },
            "parts": {
              "type": "integer",
              "minimum": 0
            },
            "listings": {
              "type": "integer",
              "minimum": 0
            },
            "listing_events": {
              "type": "integer",
              "minimum": 0
            },
            "listing_metrics": {
              "type": "integer",
              "minimum": 0
            },
            "sales": {
              "type": "integer",
              "minimum": 0
            },
            "sale_events": {
              "type": "integer",
              "minimum": 0
            },
            "tombstones": {
              "type": "integer",
              "minimum": 0
            }
          }
        }
      },
      "allOf": [
        {
          "if": {
            "required": [
              "mode"
            ],
            "properties": {
              "mode": {
                "const": "delta"
              }
            }
          },
          "then": {
            "required": [
              "period_from",
              "period_to"
            ],
            "properties": {
              "period_from": {
                "type": "string",
                "format": "date-time"
              },
              "period_to": {
                "type": "string",
                "format": "date-time"
              }
            }
          }
        },
        {
          "if": {
            "required": [
              "mode"
            ],
            "properties": {
              "mode": {
                "const": "full_snapshot"
              }
            }
          },
          "then": {
            "required": [
              "snapshot_at",
              "scope",
              "record_counts"
            ],
            "properties": {
              "snapshot_at": {
                "type": "string",
                "format": "date-time"
              },
              "scope": {
                "type": "object"
              },
              "record_counts": {
                "type": "object"
              }
            }
          }
        }
      ]
    },
    "equipmentCode": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "system",
        "code"
      ],
      "properties": {
        "system": {
          "enum": [
            "pr",
            "sa",
            "manufacturer",
            "other"
          ]
        },
        "code": {
          "type": "string",
          "minLength": 1,
          "maxLength": 100
        },
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 500
        }
      }
    },
    "engine": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "code": {
          "type": "string",
          "minLength": 1,
          "maxLength": 100
        },
        "fuel_type": {
          "enum": [
            "petrol",
            "diesel",
            "electric",
            "hybrid_petrol",
            "hybrid_diesel",
            "lpg",
            "cng",
            "hydrogen",
            "other",
            "unknown"
          ]
        },
        "power_kw": {
          "type": "integer",
          "minimum": 0,
          "maximum": 5000
        },
        "displacement_ccm": {
          "type": "integer",
          "minimum": 0,
          "maximum": 30000
        }
      }
    },
    "transmission": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "code": {
          "type": "string",
          "minLength": 1,
          "maxLength": 100
        },
        "type": {
          "enum": [
            "manual",
            "automatic",
            "automated_manual",
            "cvt",
            "dual_clutch",
            "single_speed",
            "other",
            "unknown"
          ]
        },
        "gears": {
          "type": "integer",
          "minimum": 1,
          "maximum": 30
        }
      }
    },
    "vehicleDamage": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "overall_condition"
      ],
      "properties": {
        "overall_condition": {
          "enum": [
            "complete",
            "accident_damaged",
            "mechanical_damage",
            "fire_damage",
            "flood_damage",
            "vandalism",
            "incomplete",
            "unknown"
          ]
        },
        "damage_zones": {
          "type": "array",
          "uniqueItems": true,
          "items": {
            "enum": [
              "front",
              "front_left",
              "front_right",
              "rear",
              "rear_left",
              "rear_right",
              "left_side",
              "right_side",
              "roof",
              "underbody",
              "interior",
              "engine_bay",
              "multiple",
              "unknown"
            ]
          }
        },
        "driveable": {
          "type": [
            "boolean",
            "null"
          ]
        },
        "engine_running": {
          "type": [
            "boolean",
            "null"
          ]
        },
        "description": {
          "$ref": "#/$defs/optionalText"
        }
      }
    },
    "vehicle": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "source_vehicle_id",
        "source_location_id",
        "vin",
        "status",
        "status_changed_at",
        "acquired_at",
        "dismantled_at",
        "mileage_km",
        "damage",
        "updated_at"
      ],
      "properties": {
        "source_vehicle_id": {
          "$ref": "#/$defs/sourceId"
        },
        "source_location_id": {
          "$ref": "#/$defs/sourceId"
        },
        "vin": {
          "type": "string",
          "pattern": "^[A-HJ-NPR-Z0-9]{17}$"
        },
        "status": {
          "enum": [
            "received",
            "in_dismantling",
            "dismantled",
            "sold_complete",
            "recycled",
            "disposed",
            "unknown"
          ]
        },
        "status_changed_at": {
          "type": "string",
          "format": "date-time"
        },
        "acquired_at": {
          "$ref": "#/$defs/nullableDateTime"
        },
        "dismantled_at": {
          "$ref": "#/$defs/nullableDateTime"
        },
        "mileage_km": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": 0,
          "maximum": 10000000
        },
        "mileage_source": {
          "enum": [
            "odometer",
            "document",
            "estimated",
            "unknown"
          ]
        },
        "manufacturer": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "model": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "series": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "variant": {
          "type": "string",
          "minLength": 1,
          "maxLength": 300
        },
        "platform": {
          "type": "string",
          "minLength": 1,
          "maxLength": 100
        },
        "model_year": {
          "type": "integer",
          "minimum": 1886,
          "maximum": 2100
        },
        "production_date": {
          "type": "string",
          "format": "date"
        },
        "first_registration_date": {
          "type": "string",
          "format": "date"
        },
        "hsn": {
          "type": "string",
          "minLength": 1,
          "maxLength": 20
        },
        "tsn": {
          "type": "string",
          "minLength": 1,
          "maxLength": 20
        },
        "k_type_ids": {
          "type": "array",
          "uniqueItems": true,
          "items": {
            "type": "integer",
            "minimum": 1
          }
        },
        "nat_codes": {
          "type": "array",
          "uniqueItems": true,
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          }
        },
        "market_country": {
          "$ref": "#/$defs/countryCode"
        },
        "body_type": {
          "type": "string",
          "minLength": 1,
          "maxLength": 100
        },
        "drive_type": {
          "enum": [
            "front_wheel",
            "rear_wheel",
            "all_wheel",
            "other",
            "unknown"
          ]
        },
        "engine": {
          "$ref": "#/$defs/engine"
        },
        "transmission": {
          "$ref": "#/$defs/transmission"
        },
        "equipment_codes": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/equipmentCode"
          }
        },
        "damage": {
          "$ref": "#/$defs/vehicleDamage"
        },
        "economics": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/economicEntry"
          }
        },
        "data_quality_flags": {
          "type": "array",
          "uniqueItems": true,
          "items": {
            "enum": [
              "vin_unverified",
              "mileage_unknown",
              "technical_data_incomplete",
              "damage_data_incomplete",
              "historical_record"
            ]
          }
        },
        "updated_at": {
          "type": "string",
          "format": "date-time"
        }
      }
    },
    "oeNumber": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "raw",
        "manufacturer",
        "relation",
        "evidence"
      ],
      "properties": {
        "raw": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "normalized": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "manufacturer": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "relation": {
          "enum": [
            "primary",
            "alternative",
            "supersedes",
            "superseded_by",
            "interchangeable"
          ]
        },
        "evidence": {
          "enum": [
            "part_label",
            "vehicle_system",
            "partner_catalog",
            "external_catalog",
            "manual",
            "unknown"
          ]
        },
        "confidence": {
          "type": "number",
          "minimum": 0,
          "maximum": 1
        }
      }
    },
    "referenceNumber": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "raw",
        "type"
      ],
      "properties": {
        "raw": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "normalized": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "type": {
          "enum": [
            "aftermarket",
            "supplier",
            "barcode",
            "internal",
            "other"
          ]
        },
        "issuer": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        }
      }
    },
    "partCategory": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "source_name"
      ],
      "properties": {
        "source_code": {
          "type": "string",
          "minLength": 1,
          "maxLength": 100
        },
        "source_name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 300
        },
        "normalized_code": {
          "type": "string",
          "minLength": 1,
          "maxLength": 100
        }
      }
    },
    "partPosition": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "area": {
          "enum": [
            "front",
            "rear",
            "front_axle",
            "rear_axle",
            "engine_bay",
            "interior",
            "roof",
            "underbody",
            "other",
            "not_applicable",
            "unknown"
          ]
        },
        "side": {
          "enum": [
            "left",
            "right",
            "center",
            "not_applicable",
            "unknown"
          ]
        },
        "detail": {
          "type": "string",
          "minLength": 1,
          "maxLength": 300
        }
      }
    },
    "partCondition": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "condition_code",
        "test_status",
        "completeness"
      ],
      "properties": {
        "condition_code": {
          "enum": [
            "new",
            "used",
            "refurbished",
            "defective",
            "for_parts",
            "unknown"
          ]
        },
        "quality_grade": {
          "enum": [
            "A",
            "B",
            "C",
            "D",
            "unknown"
          ]
        },
        "test_status": {
          "enum": [
            "passed",
            "failed",
            "partial",
            "not_tested",
            "unknown"
          ]
        },
        "tested_at": {
          "$ref": "#/$defs/nullableDateTime"
        },
        "completeness": {
          "enum": [
            "complete",
            "incomplete",
            "unknown"
          ]
        },
        "defects": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 500
          }
        },
        "refurbished": {
          "type": [
            "boolean",
            "null"
          ]
        },
        "note": {
          "$ref": "#/$defs/optionalText"
        }
      }
    },
    "fitment": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "manufacturer",
        "model",
        "evidence",
        "confidence"
      ],
      "properties": {
        "manufacturer": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "model": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "series": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "variant": {
          "type": "string",
          "minLength": 1,
          "maxLength": 300
        },
        "production_from": {
          "type": "string",
          "format": "date"
        },
        "production_to": {
          "type": "string",
          "format": "date"
        },
        "k_type_ids": {
          "type": "array",
          "uniqueItems": true,
          "items": {
            "type": "integer",
            "minimum": 1
          }
        },
        "engine_codes": {
          "type": "array",
          "uniqueItems": true,
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          }
        },
        "transmission_codes": {
          "type": "array",
          "uniqueItems": true,
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          }
        },
        "evidence": {
          "enum": [
            "proven_donor_vehicle",
            "oe_catalog",
            "partner_catalog",
            "external_catalog",
            "manual"
          ]
        },
        "confidence": {
          "type": "number",
          "minimum": 0,
          "maximum": 1
        }
      }
    },
    "part": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "source_part_id",
        "source_location_id",
        "source_vehicle_id",
        "inventory_sku",
        "status",
        "status_changed_at",
        "oe_numbers",
        "name",
        "category",
        "quantity",
        "unit_type",
        "condition",
        "removed_at",
        "updated_at"
      ],
      "properties": {
        "source_part_id": {
          "$ref": "#/$defs/sourceId"
        },
        "source_location_id": {
          "$ref": "#/$defs/sourceId"
        },
        "source_vehicle_id": {
          "$ref": "#/$defs/sourceId"
        },
        "inventory_sku": {
          "$ref": "#/$defs/sourceId"
        },
        "serial_number": {
          "type": "string",
          "minLength": 1,
          "maxLength": 300
        },
        "status": {
          "enum": [
            "on_vehicle",
            "removed",
            "available",
            "listed",
            "reserved",
            "sold",
            "returned",
            "recycled",
            "disposed",
            "missing",
            "unknown"
          ]
        },
        "status_changed_at": {
          "type": "string",
          "format": "date-time"
        },
        "oe_numbers": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "$ref": "#/$defs/oeNumber"
          },
          "contains": {
            "type": "object",
            "required": [
              "relation"
            ],
            "properties": {
              "relation": {
                "const": "primary"
              }
            }
          },
          "minContains": 1,
          "maxContains": 1
        },
        "reference_numbers": {
          "type": "array",
          "uniqueItems": true,
          "items": {
            "$ref": "#/$defs/referenceNumber"
          }
        },
        "manufacturer": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 500
        },
        "category": {
          "$ref": "#/$defs/partCategory"
        },
        "quantity": {
          "type": "integer",
          "minimum": 1,
          "maximum": 1000000
        },
        "unit_type": {
          "enum": [
            "single",
            "set",
            "kit",
            "lot"
          ]
        },
        "position": {
          "$ref": "#/$defs/partPosition"
        },
        "condition": {
          "$ref": "#/$defs/partCondition"
        },
        "removed_at": {
          "$ref": "#/$defs/nullableDateTime"
        },
        "hardware_version": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "software_version": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "color_code": {
          "type": "string",
          "minLength": 1,
          "maxLength": 100
        },
        "storage_location": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "images": {
          "type": "array",
          "uniqueItems": true,
          "items": {
            "type": "string",
            "format": "uri"
          }
        },
        "fitments": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/fitment"
          }
        },
        "economics": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/economicEntry"
          }
        },
        "data_quality_flags": {
          "type": "array",
          "uniqueItems": true,
          "items": {
            "enum": [
              "oe_unverified",
              "vehicle_link_uncertain",
              "condition_incomplete",
              "quantity_aggregated",
              "history_incomplete",
              "historical_record"
            ]
          }
        },
        "updated_at": {
          "type": "string",
          "format": "date-time"
        }
      }
    },
    "channel": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "source_channel_id",
        "type",
        "name",
        "market_country"
      ],
      "properties": {
        "source_channel_id": {
          "$ref": "#/$defs/sourceId"
        },
        "type": {
          "enum": [
            "marketplace",
            "webshop",
            "direct",
            "wholesale",
            "offline",
            "other"
          ]
        },
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "market_country": {
          "$ref": "#/$defs/countryCode"
        }
      }
    },
    "listingItem": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "source_part_id",
        "quantity"
      ],
      "properties": {
        "source_part_id": {
          "$ref": "#/$defs/sourceId"
        },
        "quantity": {
          "type": "integer",
          "minimum": 1,
          "maximum": 1000000
        }
      }
    },
    "listingEndReason": {
      "enum": [
        "sold_on_channel",
        "sold_elsewhere",
        "expired",
        "withdrawn_by_seller",
        "damaged",
        "scrapped",
        "duplicate",
        "channel_policy",
        "missing_from_source",
        "unknown"
      ]
    },
    "listing": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "source_listing_id",
        "source_location_id",
        "items",
        "channel",
        "listed_at",
        "first_seen_at",
        "last_seen_at",
        "status",
        "status_changed_at",
        "status_reason",
        "initial_ask_price",
        "last_ask_price",
        "shipping_price",
        "updated_at"
      ],
      "properties": {
        "source_listing_id": {
          "$ref": "#/$defs/sourceId"
        },
        "source_location_id": {
          "$ref": "#/$defs/sourceId"
        },
        "relist_of_listing_id": {
          "$ref": "#/$defs/sourceId"
        },
        "items": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "$ref": "#/$defs/listingItem"
          }
        },
        "channel": {
          "$ref": "#/$defs/channel"
        },
        "listing_url": {
          "type": "string",
          "format": "uri"
        },
        "listed_at": {
          "$ref": "#/$defs/nullableDateTime"
        },
        "first_seen_at": {
          "type": "string",
          "format": "date-time"
        },
        "last_seen_at": {
          "type": "string",
          "format": "date-time"
        },
        "status": {
          "enum": [
            "draft",
            "active",
            "paused",
            "reserved",
            "sold",
            "withdrawn",
            "expired",
            "scrapped",
            "unknown"
          ]
        },
        "status_changed_at": {
          "type": "string",
          "format": "date-time"
        },
        "status_reason": {
          "oneOf": [
            {
              "$ref": "#/$defs/listingEndReason"
            },
            {
              "type": "null"
            }
          ]
        },
        "initial_ask_price": {
          "$ref": "#/$defs/money"
        },
        "last_ask_price": {
          "$ref": "#/$defs/money"
        },
        "shipping_price": {
          "$ref": "#/$defs/nullableMoney"
        },
        "core_charge": {
          "$ref": "#/$defs/nullableMoney"
        },
        "warranty_months": {
          "type": "integer",
          "minimum": 0,
          "maximum": 240
        },
        "return_window_days": {
          "type": "integer",
          "minimum": 0,
          "maximum": 3650
        },
        "updated_at": {
          "type": "string",
          "format": "date-time"
        }
      },
      "allOf": [
        {
          "if": {
            "required": [
              "status"
            ],
            "properties": {
              "status": {
                "enum": [
                  "sold",
                  "withdrawn",
                  "expired",
                  "scrapped"
                ]
              }
            }
          },
          "then": {
            "properties": {
              "status_reason": {
                "$ref": "#/$defs/listingEndReason"
              }
            }
          }
        }
      ]
    },
    "listingEvent": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "source_event_id",
        "source_listing_id",
        "type",
        "occurred_at"
      ],
      "properties": {
        "source_event_id": {
          "$ref": "#/$defs/sourceId"
        },
        "source_listing_id": {
          "$ref": "#/$defs/sourceId"
        },
        "type": {
          "enum": [
            "listed",
            "relisted",
            "price_changed",
            "quantity_changed",
            "reserved",
            "reservation_released",
            "paused",
            "reactivated",
            "sold",
            "withdrawn",
            "expired",
            "scrapped",
            "corrected"
          ]
        },
        "occurred_at": {
          "type": "string",
          "format": "date-time"
        },
        "ask_price": {
          "$ref": "#/$defs/money"
        },
        "quantity": {
          "type": "integer",
          "minimum": 0,
          "maximum": 1000000
        },
        "end_reason": {
          "$ref": "#/$defs/listingEndReason"
        },
        "source_sale_id": {
          "$ref": "#/$defs/sourceId"
        },
        "corrects_event_id": {
          "$ref": "#/$defs/sourceId"
        },
        "note": {
          "$ref": "#/$defs/optionalText"
        }
      },
      "allOf": [
        {
          "if": {
            "required": [
              "type"
            ],
            "properties": {
              "type": {
                "enum": [
                  "listed",
                  "relisted",
                  "price_changed"
                ]
              }
            }
          },
          "then": {
            "required": [
              "ask_price"
            ],
            "properties": {
              "ask_price": {
                "$ref": "#/$defs/money"
              }
            }
          }
        },
        {
          "if": {
            "required": [
              "type"
            ],
            "properties": {
              "type": {
                "const": "quantity_changed"
              }
            }
          },
          "then": {
            "required": [
              "quantity"
            ],
            "properties": {
              "quantity": {
                "type": "integer",
                "minimum": 0,
                "maximum": 1000000
              }
            }
          }
        },
        {
          "if": {
            "required": [
              "type"
            ],
            "properties": {
              "type": {
                "enum": [
                  "withdrawn",
                  "expired",
                  "scrapped"
                ]
              }
            }
          },
          "then": {
            "required": [
              "end_reason"
            ],
            "properties": {
              "end_reason": {
                "$ref": "#/$defs/listingEndReason"
              }
            }
          }
        },
        {
          "if": {
            "required": [
              "type"
            ],
            "properties": {
              "type": {
                "const": "sold"
              }
            }
          },
          "then": {
            "required": [
              "source_sale_id"
            ],
            "properties": {
              "source_sale_id": {
                "$ref": "#/$defs/sourceId"
              }
            }
          }
        },
        {
          "if": {
            "required": [
              "type"
            ],
            "properties": {
              "type": {
                "const": "corrected"
              }
            }
          },
          "then": {
            "required": [
              "corrects_event_id",
              "note"
            ],
            "properties": {
              "corrects_event_id": {
                "$ref": "#/$defs/sourceId"
              },
              "note": {
                "$ref": "#/$defs/optionalText"
              }
            }
          }
        }
      ]
    },
    "listingMetric": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "source_metric_id",
        "source_listing_id",
        "measurement_type",
        "observed_at"
      ],
      "properties": {
        "source_metric_id": {
          "$ref": "#/$defs/sourceId"
        },
        "source_listing_id": {
          "$ref": "#/$defs/sourceId"
        },
        "measurement_type": {
          "enum": [
            "cumulative",
            "period"
          ]
        },
        "observed_at": {
          "type": "string",
          "format": "date-time"
        },
        "period_from": {
          "type": "string",
          "format": "date-time"
        },
        "period_to": {
          "type": "string",
          "format": "date-time"
        },
        "impressions": {
          "type": "integer",
          "minimum": 0
        },
        "views": {
          "type": "integer",
          "minimum": 0
        },
        "watchers": {
          "type": "integer",
          "minimum": 0
        },
        "inquiries": {
          "type": "integer",
          "minimum": 0
        },
        "offers": {
          "type": "integer",
          "minimum": 0
        },
        "add_to_cart": {
          "type": "integer",
          "minimum": 0
        }
      },
      "anyOf": [
        {
          "required": [
            "impressions"
          ],
          "properties": {
            "impressions": {
              "type": "integer",
              "minimum": 0
            }
          }
        },
        {
          "required": [
            "views"
          ],
          "properties": {
            "views": {
              "type": "integer",
              "minimum": 0
            }
          }
        },
        {
          "required": [
            "watchers"
          ],
          "properties": {
            "watchers": {
              "type": "integer",
              "minimum": 0
            }
          }
        },
        {
          "required": [
            "inquiries"
          ],
          "properties": {
            "inquiries": {
              "type": "integer",
              "minimum": 0
            }
          }
        },
        {
          "required": [
            "offers"
          ],
          "properties": {
            "offers": {
              "type": "integer",
              "minimum": 0
            }
          }
        },
        {
          "required": [
            "add_to_cart"
          ],
          "properties": {
            "add_to_cart": {
              "type": "integer",
              "minimum": 0
            }
          }
        }
      ],
      "allOf": [
        {
          "if": {
            "required": [
              "measurement_type"
            ],
            "properties": {
              "measurement_type": {
                "const": "period"
              }
            }
          },
          "then": {
            "required": [
              "period_from",
              "period_to"
            ],
            "properties": {
              "period_from": {
                "type": "string",
                "format": "date-time"
              },
              "period_to": {
                "type": "string",
                "format": "date-time"
              }
            }
          }
        }
      ]
    },
    "saleItem": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "source_part_id",
        "quantity",
        "item_amount"
      ],
      "properties": {
        "source_part_id": {
          "$ref": "#/$defs/sourceId"
        },
        "quantity": {
          "type": "integer",
          "minimum": 1,
          "maximum": 1000000
        },
        "item_amount": {
          "$ref": "#/$defs/money"
        },
        "discount_amount": {
          "$ref": "#/$defs/nullableMoney"
        }
      }
    },
    "saleEventItem": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "source_part_id",
        "quantity"
      ],
      "properties": {
        "source_part_id": {
          "$ref": "#/$defs/sourceId"
        },
        "quantity": {
          "type": "integer",
          "minimum": 1,
          "maximum": 1000000
        },
        "amount": {
          "$ref": "#/$defs/money"
        }
      }
    },
    "saleEvent": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "source_sale_event_id",
        "type",
        "occurred_at"
      ],
      "properties": {
        "source_sale_event_id": {
          "$ref": "#/$defs/sourceId"
        },
        "type": {
          "enum": [
            "ordered",
            "paid",
            "fulfilled",
            "completed",
            "cancelled",
            "return_opened",
            "partially_returned",
            "returned",
            "partially_refunded",
            "refunded"
          ]
        },
        "occurred_at": {
          "type": "string",
          "format": "date-time"
        },
        "amount": {
          "$ref": "#/$defs/nullableMoney"
        },
        "items": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "$ref": "#/$defs/saleEventItem"
          }
        },
        "reason": {
          "enum": [
            "buyer_cancelled",
            "seller_cancelled",
            "not_as_described",
            "defective",
            "incompatible",
            "damaged_in_transit",
            "changed_mind",
            "not_collected",
            "other",
            "unknown"
          ]
        },
        "note": {
          "$ref": "#/$defs/optionalText"
        }
      },
      "allOf": [
        {
          "if": {
            "required": [
              "type"
            ],
            "properties": {
              "type": {
                "enum": [
                  "return_opened",
                  "partially_returned",
                  "returned",
                  "partially_refunded",
                  "refunded"
                ]
              }
            }
          },
          "then": {
            "required": [
              "items"
            ],
            "properties": {
              "items": {
                "type": "array",
                "minItems": 1
              }
            }
          }
        },
        {
          "if": {
            "required": [
              "type"
            ],
            "properties": {
              "type": {
                "enum": [
                  "partially_refunded",
                  "refunded"
                ]
              }
            }
          },
          "then": {
            "required": [
              "amount"
            ],
            "properties": {
              "amount": {
                "$ref": "#/$defs/money"
              }
            }
          }
        }
      ]
    },
    "sale": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "source_sale_id",
        "source_location_id",
        "channel",
        "sold_at",
        "status",
        "status_changed_at",
        "items",
        "shipping_charged",
        "platform_fee",
        "payment_fee",
        "refund_amount",
        "events",
        "updated_at"
      ],
      "properties": {
        "source_sale_id": {
          "$ref": "#/$defs/sourceId"
        },
        "source_location_id": {
          "$ref": "#/$defs/sourceId"
        },
        "source_listing_id": {
          "$ref": "#/$defs/sourceId"
        },
        "channel": {
          "$ref": "#/$defs/channel"
        },
        "sold_at": {
          "type": "string",
          "format": "date-time"
        },
        "status": {
          "enum": [
            "pending",
            "paid",
            "fulfilled",
            "completed",
            "cancelled",
            "partially_returned",
            "returned",
            "partially_refunded",
            "refunded"
          ]
        },
        "status_changed_at": {
          "type": "string",
          "format": "date-time"
        },
        "items": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "$ref": "#/$defs/saleItem"
          }
        },
        "shipping_charged": {
          "$ref": "#/$defs/nullableMoney"
        },
        "platform_fee": {
          "$ref": "#/$defs/nullableMoney"
        },
        "payment_fee": {
          "$ref": "#/$defs/nullableMoney"
        },
        "refund_amount": {
          "$ref": "#/$defs/nullableMoney"
        },
        "buyer_segment": {
          "enum": [
            "b2c",
            "b2b",
            "unknown"
          ]
        },
        "buyer_country": {
          "$ref": "#/$defs/countryCode"
        },
        "events": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/saleEvent"
          }
        },
        "updated_at": {
          "type": "string",
          "format": "date-time"
        }
      }
    },
    "tombstone": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "entity_type",
        "source_id",
        "source_location_id",
        "source_channel_id",
        "deleted_at",
        "reason"
      ],
      "properties": {
        "entity_type": {
          "enum": [
            "vehicle",
            "part",
            "listing",
            "listing_event",
            "listing_metric",
            "sale",
            "sale_event"
          ]
        },
        "source_id": {
          "$ref": "#/$defs/sourceId"
        },
        "source_location_id": {
          "$ref": "#/$defs/sourceId"
        },
        "source_channel_id": {
          "oneOf": [
            {
              "$ref": "#/$defs/sourceId"
            },
            {
              "type": "null"
            }
          ]
        },
        "deleted_at": {
          "type": "string",
          "format": "date-time"
        },
        "reason": {
          "enum": [
            "duplicate",
            "source_correction",
            "source_deleted",
            "data_protection",
            "other"
          ]
        },
        "note": {
          "$ref": "#/$defs/optionalText"
        }
      },
      "allOf": [
        {
          "if": {
            "required": [
              "entity_type"
            ],
            "properties": {
              "entity_type": {
                "enum": [
                  "vehicle",
                  "part"
                ]
              }
            }
          },
          "then": {
            "properties": {
              "source_channel_id": {
                "type": "null"
              }
            }
          },
          "else": {
            "properties": {
              "source_channel_id": {
                "$ref": "#/$defs/sourceId"
              }
            }
          }
        }
      ]
    }
  }
}
