{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/nashboard-ai/json-schema/nashboard-ai-bulk-enrich-response-schema.json",
  "title": "BulkEnrichResponse",
  "x-generated": "2026-11-19",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/nashboard-ai-openapi.json#/components/schemas/BulkEnrichResponse",
  "type": "object",
  "required": [
    "results",
    "summary"
  ],
  "properties": {
    "results": {
      "type": "array",
      "items": {
        "oneOf": [
          {
            "type": "object",
            "required": [
              "index",
              "status",
              "result"
            ],
            "properties": {
              "index": {
                "type": "integer",
                "minimum": 0
              },
              "status": {
                "type": "string",
                "enum": [
                  "ok"
                ]
              },
              "result": {
                "$ref": "#/$defs/EnrichResponse"
              }
            },
            "additionalProperties": false
          },
          {
            "type": "object",
            "required": [
              "index",
              "status",
              "error_code",
              "message"
            ],
            "properties": {
              "index": {
                "type": "integer",
                "minimum": 0
              },
              "status": {
                "type": "string",
                "enum": [
                  "error"
                ]
              },
              "error_code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              }
            },
            "additionalProperties": false
          }
        ]
      }
    },
    "summary": {
      "type": "object",
      "required": [
        "total",
        "ok",
        "error"
      ],
      "properties": {
        "total": {
          "type": "integer"
        },
        "ok": {
          "type": "integer"
        },
        "error": {
          "type": "integer"
        }
      },
      "additionalProperties": false
    }
  },
  "additionalProperties": false,
  "$defs": {
    "EnrichResponse": {
      "type": "object",
      "required": [
        "request_id",
        "match_score",
        "match_method",
        "ai_generated",
        "counterparties",
        "is_recurring",
        "homoglyph_detected",
        "ai_confidence",
        "latency_ms"
      ],
      "properties": {
        "request_id": {
          "type": "string",
          "format": "uuid"
        },
        "merchant_id": {
          "type": [
            "string",
            "null"
          ],
          "format": "uuid",
          "description": "Matched merchant ID, or null on no-match."
        },
        "merchant": {
          "type": [
            "object",
            "null"
          ],
          "description": "Resolved merchant object (null on no-match). Carries additional hierarchy/standards fields not all enumerated here.",
          "properties": {
            "name": {
              "type": "string"
            },
            "name_localized": {
              "type": [
                "object",
                "null"
              ],
              "additionalProperties": {
                "type": "string"
              },
              "description": "Localized display names keyed by locale (e.g. en, ar, ru)."
            },
            "logo_url": {
              "type": [
                "string",
                "null"
              ]
            },
            "confidence_tier": {
              "type": "integer"
            }
          },
          "additionalProperties": true
        },
        "match_score": {
          "type": "number",
          "minimum": 0,
          "maximum": 1,
          "description": "Customer-facing retrieval confidence 0-1. Distinct from ai_confidence."
        },
        "match_method": {
          "type": "string",
          "description": "How the match was determined (e.g. exact, fuzzy, ai_haiku, ai_sonnet, no_match)."
        },
        "ai_generated": {
          "type": "boolean",
          "description": "True only when the AI disambiguation step produced/altered the returned match (EU AI Act Art. 50)."
        },
        "ai_confidence": {
          "type": [
            "number",
            "null"
          ],
          "description": "AI self-reported confidence 0-1 when AI fired; null otherwise."
        },
        "counterparties": {
          "type": "array",
          "description": "Rail-aware counterparty provenance (e.g. BNPL chains).",
          "items": {
            "type": "object",
            "additionalProperties": true
          }
        },
        "is_recurring": {
          "type": "boolean",
          "description": "True when the merchant has a known subscription pattern."
        },
        "recurrence": {
          "type": [
            "object",
            "null"
          ],
          "description": "Recurrence cadence details; null when is_recurring is false.",
          "additionalProperties": true
        },
        "homoglyph_detected": {
          "type": "boolean",
          "description": "Fraud signal: true when the descriptor mixes lookalike scripts (e.g. Cyrillic+Latin)."
        },
        "latency_ms": {
          "type": "integer",
          "description": "Server-side pipeline latency in ms."
        },
        "cache_hit": {
          "type": "boolean"
        },
        "category": {
          "type": "object",
          "description": "Taxonomy classification result.",
          "additionalProperties": true
        },
        "hierarchy": {
          "type": [
            "object",
            "null"
          ],
          "description": "Brand → operator → location hierarchy.",
          "additionalProperties": true
        },
        "alternates": {
          "type": "array",
          "description": "Top-N alternate merchant candidates.",
          "items": {
            "type": "object",
            "properties": {
              "merchant_id": {
                "type": "string",
                "format": "uuid"
              },
              "name": {
                "type": "string"
              },
              "confidence": {
                "type": "number"
              }
            },
            "additionalProperties": true
          }
        }
      },
      "additionalProperties": true,
      "description": "W5a flat EnrichResponse. additionalProperties:true — fields such as merchant{}, hierarchy, bin_signal, debug fields (rank_gap, nb_extensions) are present but not fully closed in this schema."
    }
  }
}