{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://autoagentprotocol.org/v3.2/schemas/inventory-search-request.schema.json",
  "title": "InventorySearchRequest",
  "description": "Search inventory through MCP, A2A or PAP using the same typed payload. Filter fields combine with AND; values within an array combine with OR, except features_all. Unsupported filters MUST be rejected, never ignored. Use the advertised inventory capabilities to discover supported filters and sort fields. Cursor pagination traverses the full matching set.",
  "type": "object",
  "examples": [
    {
      "type": "inventory.search.request",
      "filters": {
        "make": ["Honda"],
        "condition": ["new"],
        "body": ["suv"],
        "price_max": 40000,
        "year_min": 2023
      },
      "pagination": { "limit": 25 },
      "sort": { "field": "price", "order": "asc" },
      "privacy": { "anonymous": true }
    }
  ],
  "properties": {
    "type": { "const": "inventory.search.request" },
    "currency": {
      "$ref": "./_primitives/currency.schema.json",
      "description": "Single currency of the matching inventory and all price bounds, price sorts and price facets. Omit to use capabilities.default_currency, or USD when that capability is absent. Every matched vehicle has this effective currency, including listings without a price. No foreign-exchange conversion or country inference occurs. A schema-valid currency not advertised by capabilities.currencies returns SCHEMA_VALIDATION_FAILED at /currency."
    },
    "mileage_unit": {
      "$ref": "./_primitives/mileage-unit.schema.json",
      "description": "Unit for filters.mileage_max, mileage sorting and mileage_range. Omit to use capabilities.default_mileage_unit, or mi when absent. Compare known odometers after exact conversion using 1 mi = 1.609344 km, without rounding before filtering or sorting. Returned Vehicle.mileage stays in each vehicle's explicitly labelled native unit. This does not change radius_mi, distance_mi or electric_range_mi."
    },
    "filters": {
      "$ref": "#/$defs/filters",
      "description": "Optional filter block. All fields optional; absent fields mean 'no constraint'."
    },
    "pagination": {
      "type": "object",
      "description": "Omit cursor and skip for the first page. Continue with the previous response's next_cursor and the same effective currency, mileage_unit, filters, sort and limit. Offset entry is optional and must be advertised. Cursor and skip are mutually exclusive. The server publishes its default_limit and max_limit; limits above max_limit are rejected.",
      "properties": {
        "skip": { "type": "integer", "minimum": 0, "description": "Number of results to skip from the start of the matching set.", "examples": [0, 25] },
        "limit": {"type": "integer", "minimum": 1, "maximum": 100, "description": "Maximum results on this page, up to the deployment's advertised max_limit.", "examples": [25]},
        "cursor": {
          "type": "string",
          "minLength": 1,
          "maxLength": 4096,
          "description": "Opaque continuation token. Do not construct, decode or edit it. Invalid, expired or query-mismatched tokens return INVALID_CURSOR."
        }
      },
      "additionalProperties": false,
      "not": {
        "required": [
          "cursor",
          "skip"
        ]
      }
    },
    "sort": {
      "type": "object",
      "description": "Result ordering. Default ordering is dealer-defined.",
      "properties": {
        "field": {
          "type": "string",
          "enum": ["price", "list_price", "msrp", "mileage", "year", "make", "model", "stock", "updated_at", "distance_mi"],
          "description": "Primary sort field. Missing values sort last in either direction. Price fields compare only amounts in the effective query currency; mileage compares readings converted to the effective query mileage_unit without rounding. price includes mandatory dealer charges and excludes only government-required consumer charges. distance_mi requires filters.near and is straight-line distance to the vehicle's rooftop. Break ties with a stable listing identifier so cursor pages do not repeat listings.",
          "examples": ["price", "year"]
        },
        "order": { "type": "string", "enum": ["asc", "desc"], "examples": ["asc"] }
      },
      "required": ["field", "order"],
      "additionalProperties": false
    },
    "privacy": {
      "type": "object",
      "description": "Privacy hints from the buyer agent. AAP RECOMMENDS anonymous searches by default; user identity is only attached when a lead is submitted.",
      "properties": {
        "anonymous": { "type": "boolean", "description": "True when no user-identifying information is included with the request.", "examples": [true] }
      },
      "additionalProperties": false
    }
  },
  "required": ["type"],
  "additionalProperties": false,
  "$defs": {
    "filters": {
      "type": "object",
      "description": "Filter fields combine with AND. Multi-value arrays combine with OR, except features_all. Ranges are inclusive. A missing listing value never satisfies a filter. Empty arrays and inverted ranges are invalid. The near field groups one geographic point and its radius; other filters remain flat.",
      "properties": {
        "make": {"type": "array", "items": {"type": "string", "minLength": 1}, "description": "Vehicle makes to include (e.g. ['Honda','BMW']).", "examples": [["Honda"], ["Honda", "BMW"]], "minItems": 1, "uniqueItems": true},
        "model": {"type": "array", "items": {"type": "string", "minLength": 1}, "description": "Vehicle models to include.", "examples": [["CR-V"]], "minItems": 1, "uniqueItems": true},
        "trim": {"type": "array", "items": {"type": "string", "minLength": 1}, "description": "Trim levels to include.", "examples": [["EX-L"]], "minItems": 1, "uniqueItems": true},
        "condition": {
          "type": "array",
          "items": {"type": "string", "enum": ["new", "used", "cpo"], "minLength": 1},
          "description": "Sale conditions to include. Inventory uses the sale-condition vocabulary (`new` | `used` | `cpo`).",
          "examples": [["new"], ["used", "cpo"]],
          "minItems": 1,
          "uniqueItems": true
        },
        "vehicle_type": {"type": "array", "items": {"type": "string", "enum": ["car", "motorcycle", "trailer", "rv", "other"], "minLength": 1}, "description": "Vehicle types to include (e.g. ['motorcycle']). Omit to search all types; a value absent on a listing is treated as 'car'.", "examples": [["motorcycle"], ["car"]], "minItems": 1, "uniqueItems": true},
        "transmission": {"type": "array", "items": {"type": "string", "minLength": 1}, "examples": [["automatic"]], "minItems": 1, "uniqueItems": true},
        "fuel": {"type": "array", "items": {"type": "string", "minLength": 1}, "examples": [["hybrid", "bev"]], "minItems": 1, "uniqueItems": true},
        "electric_range_mi_min": { "type": "integer", "minimum": 0, "description": "Minimum electric range in miles, applied against `electric_range_mi`. Generic electric filter (EV cars and electric motorcycles).", "examples": [100] },
        "electric_range_mi_max": { "type": "integer", "minimum": 0, "description": "Maximum electric range in miles, applied against `electric_range_mi`. Generic electric filter.", "examples": [300] },
        "dc_fast_charge": { "type": "boolean", "description": "When true, include only units that support DC fast charging (matches `Vehicle.dc_fast_charge`). Generic electric filter.", "examples": [true] },
        "charge_port": {"type": "array", "items": {"type": "string", "minLength": 1}, "description": "EV charge/plug connectors to include (e.g. ['nacs','ccs']), matching `Vehicle.charge_port`.", "examples": [["nacs"]], "minItems": 1, "uniqueItems": true},
        "driveline": {"type": "array", "items": {"type": "string", "minLength": 1}, "description": "Drivetrain layouts to include (e.g. ['awd']). Car context.", "examples": [["awd"]], "minItems": 1, "uniqueItems": true},
        "body": {"type": "array", "items": {"type": "string", "minLength": 1}, "description": "Body styles / segments to include, applicable to any vehicle_type (e.g. ['sedan','suv','truck'] for cars, ['cruiser','touring'] for motorcycles).", "examples": [["suv"], ["cruiser"]], "minItems": 1, "uniqueItems": true},
        "displacement_cc_min": { "type": "integer", "minimum": 0, "description": "Minimum engine displacement in cc, applied against `displacement_cc`.", "examples": [600] },
        "displacement_cc_max": { "type": "integer", "minimum": 0, "description": "Maximum engine displacement in cc, applied against `displacement_cc`.", "examples": [1200] },
        "exterior_color": {"type": "array", "items": {"type": "string", "minLength": 1}, "examples": [["black"]], "minItems": 1, "uniqueItems": true},
        "interior_color": {"type": "array", "items": {"type": "string", "minLength": 1}, "examples": [["black"]], "minItems": 1, "uniqueItems": true},
        "rooftops": {"type": "array", "items": {"type": "string", "minLength": 1}, "description": "Exact rooftop names from this dealer's dealer.information. Dealer-scoped endpoints MAY support this filter; aggregate endpoints MUST reject it as UNSUPPORTED_FILTER rather than guess across duplicate names. Omit to search every rooftop in the endpoint's scope.", "examples": [["Demo Toyota San Francisco"]], "minItems": 1, "uniqueItems": true},
        "year_min": { "type": "integer", "minimum": 1900, "maximum": 2100, "examples": [2023] },
        "year_max": { "type": "integer", "minimum": 1900, "maximum": 2100, "examples": [2025] },
        "price_min": { "type": "integer", "minimum": 0, "description": "Minimum price in whole units of the effective query currency, applied against the authoritative advertised `price` field. Vehicles without `price` do not match this filter.", "examples": [20000] },
        "price_max": { "type": "integer", "minimum": 0, "description": "Maximum price in whole units of the effective query currency, applied against the authoritative advertised `price` field. Vehicles without `price` do not match this filter.", "examples": [40000] },
        "mileage_max": { "type": "integer", "minimum": 0, "description": "Inclusive maximum odometer in the effective query mileage_unit. Convert the known native reading exactly before comparing; a missing reading never matches.", "examples": [60000] },
        "vin": { "type": "string", "pattern": "^[A-HJ-NPR-Z0-9]{17}$", "examples": ["1HGCV1F30NA123456"] },
        "stock": { "type": "string", "examples": ["H12345"] },
        "query": {"type": "string", "minLength": 1, "maxLength": 200, "description": "Keyword search, not natural-language filter parsing. Split trimmed text on whitespace. Every case-insensitive token must occur as a substring in at least one of make, model, trim, vin, stock or features. Quotes and operators have no special meaning. Use structured fields for price, distance, equipment requirements and other constraints. The response reports query_terms.", "examples": ["Honda Civic", "Touring"], "pattern": "\\S"},
        "status": {
          "type": "array",
          "items": {
            "type": "string",
            "enum": [
              "available",
              "intransit",
              "pending"
            ],
            "minLength": 1
          },
          "description": "Availability states to include. Pending does not mean available for purchase. Out-of-stock listings never match.",
          "examples": [
            [
              "available"
            ]
          ],
          "minItems": 1,
          "uniqueItems": true
        },
        "features_all": {
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]*$",
            "maxLength": 80,
            "minLength": 1
          },
          "description": "Require every advertised feature code. Each match MUST have present feature_evidence for every requested code; unknown equipment does not match.",
          "examples": [
            [
              "adaptive_cruise_control",
              "heated_front_seats"
            ]
          ],
          "minItems": 1,
          "uniqueItems": true
        },
        "features_any": {
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]*$",
            "maxLength": 80,
            "minLength": 1
          },
          "description": "Require at least one advertised feature code. Matching codes MUST have present feature_evidence in each result. When combined with features_all, both constraints apply.",
          "examples": [
            [
              "apple_carplay",
              "android_auto"
            ]
          ],
          "minItems": 1,
          "uniqueItems": true
        },
        "near": {
          "type": "object",
          "description": "Include vehicles whose physical rooftop is within this inclusive straight-line radius. Resolve place names to a geographic point before calling. A listing with unknown rooftop coordinates cannot match. Do not substitute the group's headquarters or a delivery area.",
          "properties": {
            "latitude": {
              "type": "number",
              "minimum": -90,
              "maximum": 90
            },
            "longitude": {
              "type": "number",
              "minimum": -180,
              "maximum": 180
            },
            "radius_mi": {
              "type": "number",
              "exclusiveMinimum": 0
            }
          },
          "required": [
            "latitude",
            "longitude",
            "radius_mi"
          ],
          "additionalProperties": false,
          "examples": [
            {
              "latitude": 32.7767,
              "longitude": -96.797,
              "radius_mi": 50
            }
          ]
        }
      },
      "additionalProperties": false
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "sort": {
            "properties": {
              "field": {
                "const": "distance_mi"
              }
            },
            "required": [
              "field"
            ]
          }
        },
        "required": [
          "sort"
        ]
      },
      "then": {
        "properties": {
          "filters": {
            "required": [
              "near"
            ]
          }
        },
        "required": [
          "filters"
        ]
      }
    }
  ]
}
