{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.ironscout.ai/ids/schemas/product_detail_v1.schema.json",
  "title": "product_detail_v1",
  "description": "IDS v1 response shape for GET /api/ids/products/{canonicalProductId}. Canonical product attributes + current offers per retailer + optional compact windowed history summary (IDS §5.3). Descriptive only: no verdict/score/recommendation field exists (ADR-003/006). See https://www.ironscout.ai/.well-known/ids.md.",
  "type": "object",
  "additionalProperties": false,
  "required": ["schemaVersion", "computedAt", "product", "offers"],
  "properties": {
    "schemaVersion": { "type": "string", "const": "product_detail_v1" },
    "requestId": { "type": ["string", "null"] },
    "computedAt": { "type": "string", "format": "date-time" },
    "product": { "$ref": "#/$defs/product" },
    "offers": {
      "type": "array",
      "items": { "$ref": "#/$defs/offer" }
    },
    "historySummary": { "$ref": "#/$defs/historySummary" }
  },
  "$defs": {
    "product": {
      "type": "object",
      "additionalProperties": false,
      "required": ["canonicalProductId", "title", "caliberSlug"],
      "properties": {
        "canonicalProductId": { "type": "string" },
        "title": { "type": "string" },
        "brand": { "type": ["string", "null"] },
        "caliberSlug": { "type": ["string", "null"] },
        "grain": { "type": ["integer", "null"] },
        "caseMaterial": { "type": ["string", "null"] },
        "roundCount": { "type": ["integer", "null"] },
        "imageUrl": { "type": ["string", "null"], "format": "uri" }
      }
    },
    "offer": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "offerId",
        "retailerId",
        "retailerName",
        "inStock",
        "currentPrice",
        "observedAt",
        "provenance",
        "outUrl"
      ],
      "properties": {
        "offerId": { "type": "string" },
        "retailerId": { "type": "string" },
        "retailerName": { "type": "string" },
        "inStock": { "type": "boolean" },
        "availability": {
          "type": ["string", "null"],
          "enum": ["IN_STOCK", "OUT_OF_STOCK", "BACKORDER", "UNKNOWN", null]
        },
        "currentPrice": {
          "type": "object",
          "additionalProperties": false,
          "required": ["amount", "currency", "pricePerRound", "unitQuantity"],
          "properties": {
            "amount": { "type": "number", "minimum": 0 },
            "currency": { "type": "string" },
            "pricePerRound": { "type": ["number", "null"], "minimum": 0 },
            "unitQuantity": { "type": ["integer", "null"], "minimum": 0 }
          }
        },
        "observedAt": { "type": "string", "format": "date-time" },
        "provenance": { "$ref": "#/$defs/provenance" },
        "outUrl": { "type": "string", "format": "uri" },
        "priceContext": { "$ref": "#/$defs/priceContext" }
      }
    },
    "provenance": {
      "type": "object",
      "additionalProperties": false,
      "required": ["sourceType", "sourceId", "observationId"],
      "properties": {
        "sourceType": {
          "type": ["string", "null"],
          "enum": ["AFFILIATE_FEED", "APPROVED_SCRAPE", "DIRECT_FEED", null]
        },
        "sourceId": { "type": ["string", "null"] },
        "observationId": { "type": "string" },
        "ingestedAt": { "type": ["string", "null"], "format": "date-time" }
      }
    },
    "priceContext": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "relativePricePct": { "type": ["number", "null"] },
        "positionInRange": { "type": ["number", "null"], "minimum": 0, "maximum": 1 },
        "contextBand": { "type": ["string", "null"], "enum": ["LOW", "TYPICAL", "HIGH", null] },
        "meta": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "windowDays": { "type": ["integer", "null"], "minimum": 1 },
            "sampleCount": { "type": ["integer", "null"], "minimum": 0 },
            "asOf": { "type": ["string", "null"], "format": "date-time" }
          }
        }
      }
    },
    "historySummary": {
      "type": ["object", "null"],
      "additionalProperties": false,
      "description": "Compact windowed per-round price summary. Null when unavailable. Not full raw observations (IDS §5.3).",
      "required": ["windowDays", "computedAt", "pricePerRound", "sampleCount"],
      "properties": {
        "windowDays": { "type": "integer", "minimum": 1 },
        "windowStart": { "type": ["string", "null"], "format": "date-time" },
        "windowEnd": { "type": ["string", "null"], "format": "date-time" },
        "computedAt": { "type": "string", "format": "date-time" },
        "pricePerRound": {
          "type": ["object", "null"],
          "additionalProperties": false,
          "required": ["min", "median", "max"],
          "properties": {
            "min": { "type": ["number", "null"] },
            "median": { "type": ["number", "null"] },
            "max": { "type": ["number", "null"] }
          }
        },
        "sampleCount": { "type": "integer", "minimum": 0 }
      }
    }
  }
}
