{
  "openapi": "3.1.0",
  "info": {
    "title": "Baara : API caisse et transactions (clé machine)",
    "version": "1.0.0",
    "description": "Ventes caisse (aperçu, confirmation, lot, état d'idempotence) et lecture des transactions. Authentification : en-tête X-Baara-Api-Key. Généré depuis service-points-ledger.",
    "x-genere-depuis": "4fe8c075"
  },
  "servers": [
    {
      "url": "https://api.baara-connect.com",
      "description": "Production (et espace de test : même hôte, clé baara_test_…)"
    }
  ],
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Baara-Api-Key"
      }
    },
    "schemas": {
      "AppliedRewardItem": {
        "properties": {
          "reward_id": {
            "type": "string",
            "title": "Reward Id"
          },
          "points_redeemed": {
            "type": "integer",
            "title": "Points Redeemed",
            "default": 0
          },
          "discount_amount_xof": {
            "anyOf": [
              {
                "type": "integer"
              },
              {
                "type": "null"
              }
            ],
            "title": "Discount Amount Xof"
          },
          "currency": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Currency"
          }
        },
        "type": "object",
        "required": [
          "reward_id"
        ],
        "title": "AppliedRewardItem",
        "description": "Reward actually applied after loyalty calculation (confirm or simulated preview)."
      },
      "HTTPValidationError": {
        "properties": {
          "detail": {
            "items": {
              "$ref": "#/components/schemas/ValidationError"
            },
            "type": "array",
            "title": "Detail"
          }
        },
        "type": "object",
        "title": "HTTPValidationError"
      },
      "IdempotencyStatusItem": {
        "properties": {
          "idempotency_key": {
            "type": "string",
            "title": "Idempotency Key"
          },
          "status": {
            "type": "string",
            "title": "Status",
            "description": "confirmed | unknown"
          },
          "transaction_id": {
            "anyOf": [
              {
                "type": "string",
                "format": "uuid"
              },
              {
                "type": "null"
              }
            ],
            "title": "Transaction Id"
          }
        },
        "type": "object",
        "required": [
          "idempotency_key",
          "status"
        ],
        "title": "IdempotencyStatusItem"
      },
      "IdempotencyStatusRequest": {
        "properties": {
          "idempotency_keys": {
            "items": {
              "type": "string"
            },
            "type": "array",
            "maxItems": 100,
            "minItems": 1,
            "title": "Idempotency Keys"
          }
        },
        "additionalProperties": false,
        "type": "object",
        "required": [
          "idempotency_keys"
        ],
        "title": "IdempotencyStatusRequest"
      },
      "IdempotencyStatusResponse": {
        "properties": {
          "items": {
            "items": {
              "$ref": "#/components/schemas/IdempotencyStatusItem"
            },
            "type": "array",
            "title": "Items"
          }
        },
        "type": "object",
        "required": [
          "items"
        ],
        "title": "IdempotencyStatusResponse"
      },
      "PromotionPreviewItem": {
        "properties": {
          "id": {
            "type": "string",
            "title": "Id"
          },
          "name": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Name"
          },
          "description": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Description"
          },
          "discount_bps": {
            "anyOf": [
              {
                "type": "integer"
              },
              {
                "type": "null"
              }
            ],
            "title": "Discount Bps",
            "description": "Percent discount in basis points (10_000 = 100%)"
          },
          "discount_amount_xof": {
            "anyOf": [
              {
                "type": "integer"
              },
              {
                "type": "null"
              }
            ],
            "title": "Discount Amount Xof",
            "description": "Fixed discount in whole XOF when applicable"
          },
          "points_earned_bonus": {
            "anyOf": [
              {
                "type": "integer"
              },
              {
                "type": "null"
              }
            ],
            "title": "Points Earned Bonus"
          },
          "metadata": {
            "additionalProperties": true,
            "type": "object",
            "title": "Metadata"
          }
        },
        "type": "object",
        "required": [
          "id"
        ],
        "title": "PromotionPreviewItem",
        "description": "Single promotion applied in preview (loyalty_service can fill)."
      },
      "RedemptionInput": {
        "properties": {
          "redeem_points": {
            "type": "boolean",
            "title": "Redeem Points",
            "description": "Customer wants to redeem points (program rules apply)",
            "default": false
          },
          "selected_reward_id": {
            "anyOf": [
              {
                "type": "string",
                "format": "uuid"
              },
              {
                "type": "null"
              }
            ],
            "title": "Selected Reward Id",
            "description": "Explicitly chosen reward offer id from preview list"
          },
          "max_points_to_redeem": {
            "anyOf": [
              {
                "type": "integer",
                "maximum": 1000000000000.0,
                "minimum": 1.0
              },
              {
                "type": "null"
              }
            ],
            "title": "Max Points To Redeem",
            "description": "Optional cap on points to burn"
          }
        },
        "additionalProperties": false,
        "type": "object",
        "title": "RedemptionInput",
        "description": "Customer intention: use points and/or a specific catalog reward (sent to loyalty in context.redemption)."
      },
      "RewardOfferItem": {
        "properties": {
          "id": {
            "type": "string",
            "title": "Id"
          },
          "title": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Title"
          },
          "description": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Description"
          },
          "points_cost": {
            "anyOf": [
              {
                "type": "integer"
              },
              {
                "type": "null"
              }
            ],
            "title": "Points Cost"
          },
          "discount_type": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Discount Type",
            "description": "PERCENT | FIXED | ..."
          },
          "discount_bps": {
            "anyOf": [
              {
                "type": "integer"
              },
              {
                "type": "null"
              }
            ],
            "title": "Discount Bps",
            "description": "When PERCENT: basis points (10_000 = 100%)"
          },
          "discount_amount_xof": {
            "anyOf": [
              {
                "type": "integer"
              },
              {
                "type": "null"
              }
            ],
            "title": "Discount Amount Xof",
            "description": "When FIXED: whole XOF"
          },
          "eligible": {
            "type": "boolean",
            "title": "Eligible",
            "default": true
          },
          "ineligible_reason": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Ineligible Reason",
            "description": "English free text from loyalty. Diagnostic and last-resort fallback only; wording is not stable. Clients render ineligible_reason_code."
          },
          "ineligible_reason_code": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Ineligible Reason Code",
            "description": "Stable cause for eligible=false. Source of truth: service-loyalty engine/models/reward_ineligibility.py::RewardIneligibilityCode. Passed through verbatim — the ledger never invents or rewrites a code, and an unknown value must degrade to ineligible_reason on the client."
          },
          "ineligible_reason_params": {
            "anyOf": [
              {
                "additionalProperties": true,
                "type": "object"
              },
              {
                "type": "null"
              }
            ],
            "title": "Ineligible Reason Params",
            "description": "Numbers behind the code (points_available, points_required, min_purchase_xof), so clients never parse them back out of the sentence."
          }
        },
        "type": "object",
        "required": [
          "id"
        ],
        "title": "RewardOfferItem",
        "description": "A reward the customer may apply on this basket (from loyalty reward_offers)."
      },
      "TransactionAmountBreakdownPreview": {
        "properties": {
          "gross_amount_xof": {
            "type": "integer",
            "minimum": 0.0,
            "title": "Gross Amount Xof"
          },
          "net_after_promotions_xof": {
            "type": "integer",
            "minimum": 0.0,
            "title": "Net After Promotions Xof"
          },
          "net_after_rewards_xof": {
            "type": "integer",
            "minimum": 0.0,
            "title": "Net After Rewards Xof"
          },
          "promotion_discount_total_xof": {
            "type": "integer",
            "minimum": 0.0,
            "title": "Promotion Discount Total Xof"
          },
          "reward_discount_total_xof": {
            "type": "integer",
            "minimum": 0.0,
            "title": "Reward Discount Total Xof"
          },
          "base_points_amount_xof": {
            "type": "integer",
            "minimum": 0.0,
            "title": "Base Points Amount Xof"
          }
        },
        "type": "object",
        "required": [
          "gross_amount_xof",
          "net_after_promotions_xof",
          "net_after_rewards_xof",
          "promotion_discount_total_xof",
          "reward_discount_total_xof",
          "base_points_amount_xof"
        ],
        "title": "TransactionAmountBreakdownPreview",
        "description": "Echo of loyalty_service `amount_breakdown` on calculate-loyalty (whole XOF)."
      },
      "TransactionConfirmBatchItemResult": {
        "properties": {
          "idempotency_key": {
            "type": "string",
            "title": "Idempotency Key"
          },
          "ok": {
            "type": "boolean",
            "title": "Ok"
          },
          "result": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/TransactionConfirmResponse"
              },
              {
                "type": "null"
              }
            ]
          },
          "error_status": {
            "anyOf": [
              {
                "type": "integer"
              },
              {
                "type": "null"
              }
            ],
            "title": "Error Status"
          },
          "error_detail": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Error Detail"
          },
          "error_code": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Error Code",
            "description": "Machine-readable reason, when there is one (SUBSCRIPTION_EXPIRED, TRANSACTION_EXPIRED, ...). This is the batch path used by offline POS replay: the status alone cannot tell a condition that will clear from a permanent refusal, and the terminal must hold the former rather than drop it."
          }
        },
        "type": "object",
        "required": [
          "idempotency_key",
          "ok"
        ],
        "title": "TransactionConfirmBatchItemResult"
      },
      "TransactionConfirmBatchRequest": {
        "properties": {
          "items": {
            "items": {
              "$ref": "#/components/schemas/TransactionConfirmRequest"
            },
            "type": "array",
            "maxItems": 50,
            "minItems": 1,
            "title": "Items"
          },
          "device_sent_at": {
            "anyOf": [
              {
                "type": "string",
                "maxLength": 64
              },
              {
                "type": "null"
              }
            ],
            "title": "Device Sent At",
            "description": "RFC 3339 instant, read from the terminal's own clock, at which this batch was prepared for sending. One value per request — it describes the dispatch, not any single sale. Paired with each item's occurred_at it yields a sale age immune to clock drift, because both come from the same clock (B.2 D-1). Required: a sale that does not carry it is refused with device_sent_at_required. It stays Optional in the type only so that the refusal comes from the temporal guard, which can name the remedy, rather than from a 422 on a missing field, which cannot."
          }
        },
        "additionalProperties": false,
        "type": "object",
        "required": [
          "items"
        ],
        "title": "TransactionConfirmBatchRequest",
        "description": "POST /transactions/confirm/batch — chaque item est un corps confirm indépendant."
      },
      "TransactionConfirmBatchResponse": {
        "properties": {
          "results": {
            "items": {
              "$ref": "#/components/schemas/TransactionConfirmBatchItemResult"
            },
            "type": "array",
            "title": "Results"
          }
        },
        "type": "object",
        "required": [
          "results"
        ],
        "title": "TransactionConfirmBatchResponse"
      },
      "TransactionConfirmRequest": {
        "properties": {
          "customer_id": {
            "type": "string",
            "format": "uuid",
            "title": "Customer Id",
            "description": "Business customer id (ledger customer_id)"
          },
          "loyalty_account_id": {
            "anyOf": [
              {
                "type": "string",
                "format": "uuid"
              },
              {
                "type": "null"
              }
            ],
            "title": "Loyalty Account Id",
            "description": "Loyalty program account id (canonical; persisted to ledger loyalty_account_id)."
          },
          "account_id": {
            "anyOf": [
              {
                "type": "string",
                "format": "uuid"
              },
              {
                "type": "null"
              }
            ],
            "title": "Account Id",
            "description": "DEPRECATED alias of loyalty_account_id (accepted temporarily for compat)."
          },
          "amount_xof": {
            "anyOf": [
              {
                "type": "integer",
                "maximum": 1000000000000000.0,
                "exclusiveMinimum": 0.0
              },
              {
                "type": "null"
              }
            ],
            "title": "Amount Xof"
          },
          "items": {
            "anyOf": [
              {
                "items": {
                  "$ref": "#/components/schemas/TransactionItemInput"
                },
                "type": "array",
                "maxItems": 500
              },
              {
                "type": "null"
              }
            ],
            "title": "Items"
          },
          "store_id": {
            "type": "string",
            "format": "uuid",
            "title": "Store Id",
            "description": "Store where the transaction is executed; must be listed in JWT store_ids (or org admin)"
          },
          "idempotency_key": {
            "type": "string",
            "maxLength": 255,
            "minLength": 1,
            "title": "Idempotency Key"
          },
          "loyalty_calculation_id": {
            "anyOf": [
              {
                "type": "string",
                "format": "uuid"
              },
              {
                "type": "null"
              }
            ],
            "title": "Loyalty Calculation Id",
            "description": "Same id as preview response when client did preview; else generated by TS"
          },
          "category_ids": {
            "anyOf": [
              {
                "items": {
                  "type": "string",
                  "format": "uuid"
                },
                "type": "array",
                "maxItems": 200
              },
              {
                "type": "null"
              }
            ],
            "title": "Category Ids",
            "description": "Optional category UUIDs forwarded to loyalty context (must match preview if used)"
          },
          "gross_amount_xof": {
            "anyOf": [
              {
                "type": "integer",
                "maximum": 1000000000000000.0,
                "minimum": 0.0
              },
              {
                "type": "null"
              }
            ],
            "title": "Gross Amount Xof",
            "description": "Forwarded to calculate-loyalty (root); also overrides sum(items) for fallback breakdown when set"
          },
          "net_after_promotions_xof": {
            "anyOf": [
              {
                "type": "integer",
                "maximum": 1000000000000000.0,
                "minimum": 0.0
              },
              {
                "type": "null"
              }
            ],
            "title": "Net After Promotions Xof",
            "description": "Forwarded to calculate-loyalty (root); same resolution as earn Kafka"
          },
          "net_after_rewards_xof": {
            "anyOf": [
              {
                "type": "integer",
                "maximum": 1000000000000000.0,
                "minimum": 0.0
              },
              {
                "type": "null"
              }
            ],
            "title": "Net After Rewards Xof",
            "description": "Forwarded to calculate-loyalty; when set, also used as root amount (net payé) instead of sum(items)/amount"
          },
          "base_points_amount_xof": {
            "anyOf": [
              {
                "type": "integer",
                "maximum": 1000000000000000.0,
                "minimum": 0.0
              },
              {
                "type": "null"
              }
            ],
            "title": "Base Points Amount Xof",
            "description": "Forwarded to calculate-loyalty (root); loyalty resolves vs net_after_promotions per policy"
          },
          "promotion_discount_total_xof": {
            "anyOf": [
              {
                "type": "integer",
                "maximum": 1000000000000000.0,
                "minimum": 0.0
              },
              {
                "type": "null"
              }
            ],
            "title": "Promotion Discount Total Xof",
            "description": "Optional POS hint (audit); authoritative total is loyalty amount_breakdown.promotion_discount_total"
          },
          "reward_discount_total_xof": {
            "anyOf": [
              {
                "type": "integer",
                "maximum": 1000000000000000.0,
                "minimum": 0.0
              },
              {
                "type": "null"
              }
            ],
            "title": "Reward Discount Total Xof",
            "description": "Optional POS hint (audit); authoritative total is loyalty amount_breakdown.reward_discount_total"
          },
          "occurred_at": {
            "anyOf": [
              {
                "type": "string",
                "maxLength": 64
              },
              {
                "type": "null"
              }
            ],
            "title": "Occurred At",
            "description": "RFC 3339 business time of the sale, read from the terminal's clock. MUST carry an explicit offset: a bare local wall clock is only right where that offset happens to be zero (B.2 D-1)."
          },
          "device_sent_at": {
            "anyOf": [
              {
                "type": "string",
                "maxLength": 64
              },
              {
                "type": "null"
              }
            ],
            "title": "Device Sent At",
            "description": "RFC 3339 instant read from the terminal's clock when this request was prepared. On /confirm a single sale is a batch of one, so the field lives on the body; on /confirm/batch it lives on the envelope. Same meaning either way (B.2 D-1)."
          },
          "snapshot_validation_strict": {
            "anyOf": [
              {
                "type": "boolean"
              },
              {
                "type": "null"
              }
            ],
            "title": "Snapshot Validation Strict",
            "description": "Override default; forwarded on TransactionCreated for loyalty strict snapshot check"
          },
          "redemption": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/RedemptionInput"
              },
              {
                "type": "null"
              }
            ],
            "description": "Must match final user choice; loyalty recalculates (source of truth)"
          },
          "capture_mode": {
            "anyOf": [
              {
                "type": "string",
                "enum": [
                  "online",
                  "offline"
                ]
              },
              {
                "type": "null"
              }
            ],
            "title": "Capture Mode",
            "description": "How the terminal says the sale was entered at the counter. 'offline': the counter showed no server pricing and the customer paid the entered amount, so no monetary promotion is applied after the fact (points are still computed at occurred_at) and a points redemption is refused. Absent: unchanged behaviour. Declared by the terminal, never inferred from the route, the timestamps or source_channel."
          },
          "amount_collected_xof": {
            "anyOf": [
              {
                "type": "integer",
                "maximum": 1000000000000000.0,
                "minimum": 0.0
              },
              {
                "type": "null"
              }
            ],
            "title": "Amount Collected Xof",
            "description": "Fait de caisse : ce que le comptoir a reellement encaisse pour cette vente. Distinct des montants calcules (gross/net_after_*), qui sont le resultat du moteur de fidelite. Absent = le terminal ne declare rien ; ce n'est pas zero."
          },
          "discount_granted_xof": {
            "anyOf": [
              {
                "type": "integer",
                "maximum": 1000000000000000.0,
                "minimum": 0.0
              },
              {
                "type": "null"
              }
            ],
            "title": "Discount Granted Xof",
            "description": "Fait de caisse : la remise reellement accordee au client. Le serveur la confronte au droit reconnu a l'instant metier de la vente et rend un validation_verdict, sans jamais modifier ce montant."
          }
        },
        "additionalProperties": false,
        "type": "object",
        "required": [
          "customer_id",
          "store_id",
          "idempotency_key"
        ],
        "title": "TransactionConfirmRequest",
        "description": "POST /transactions/confirm body. idempotency_key is required."
      },
      "TransactionConfirmResponse": {
        "properties": {
          "transaction_id": {
            "type": "string",
            "format": "uuid",
            "title": "Transaction Id"
          },
          "status": {
            "type": "string",
            "title": "Status",
            "description": "CONFIRMED"
          },
          "loyalty_calculation_id": {
            "anyOf": [
              {
                "type": "string",
                "format": "uuid"
              },
              {
                "type": "null"
              }
            ],
            "title": "Loyalty Calculation Id",
            "description": "Correlation id (preview→confirm→loyalty events)"
          },
          "points_earned": {
            "type": "integer",
            "title": "Points Earned"
          },
          "created_at": {
            "anyOf": [
              {
                "type": "string",
                "format": "date-time"
              },
              {
                "type": "null"
              }
            ],
            "title": "Created At"
          },
          "points_redeemed": {
            "anyOf": [
              {
                "type": "integer"
              },
              {
                "type": "null"
              }
            ],
            "title": "Points Redeemed",
            "description": "Points burned on this transaction (loyalty); null on idempotent replay if unknown"
          },
          "discount_applied_xof": {
            "anyOf": [
              {
                "type": "integer"
              },
              {
                "type": "null"
              }
            ],
            "title": "Discount Applied Xof",
            "description": "Total monetary discount from loyalty in whole XOF (rewards + promos if combined by loyalty)"
          },
          "applied_rewards": {
            "items": {
              "$ref": "#/components/schemas/AppliedRewardItem"
            },
            "type": "array",
            "title": "Applied Rewards"
          },
          "promotions": {
            "items": {
              "$ref": "#/components/schemas/PromotionPreviewItem"
            },
            "type": "array",
            "title": "Promotions",
            "description": "Promotion lines from loyalty snapshot (includes tier_benefit synthetic promos with metadata.source)"
          },
          "validation_verdict": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Validation Verdict",
            "description": "EXACT | UNDER_GRANTED | OVER_GRANTED | NOT_DECLARED | HISTORY_UNAVAILABLE. Rapport entre la remise declaree par la caisse et celle que Baara reconnait a l'instant metier de la vente. La vente reste valide quel que soit le verdict : aucun montant n'est corrige."
          },
          "historical_eligible_discount_xof": {
            "anyOf": [
              {
                "type": "integer"
              },
              {
                "type": "null"
              }
            ],
            "title": "Historical Eligible Discount Xof",
            "description": "La remise que Baara reconnait a l'instant metier, en francs entiers. C'est le terme de comparaison du validation_verdict ; null quand le calcul n'a pas abouti a un montant."
          }
        },
        "type": "object",
        "required": [
          "transaction_id",
          "status",
          "points_earned"
        ],
        "title": "TransactionConfirmResponse",
        "description": "Response for POST /transactions/confirm. 201 created, 200 idempotent replay."
      },
      "TransactionItemInput": {
        "properties": {
          "product_id": {
            "type": "string",
            "format": "uuid",
            "title": "Product Id"
          },
          "quantity": {
            "type": "integer",
            "maximum": 1000000.0,
            "minimum": 1.0,
            "title": "Quantity"
          },
          "unit_price_xof": {
            "type": "integer",
            "maximum": 1000000000000000.0,
            "minimum": 0.0,
            "title": "Unit Price Xof",
            "description": "Unit price in whole XOF"
          },
          "product_name": {
            "anyOf": [
              {
                "type": "string",
                "maxLength": 256
              },
              {
                "type": "null"
              }
            ],
            "title": "Product Name",
            "description": "Product label at sale time. Snapshot, never re-read from the catalogue."
          },
          "category_id": {
            "anyOf": [
              {
                "type": "string",
                "format": "uuid"
              },
              {
                "type": "null"
              }
            ],
            "title": "Category Id",
            "description": "Category at sale time. Without it no category roll-up is written."
          },
          "category_label": {
            "anyOf": [
              {
                "type": "string",
                "maxLength": 256
              },
              {
                "type": "null"
              }
            ],
            "title": "Category Label",
            "description": "Category label at sale time, used when category_id is absent."
          }
        },
        "type": "object",
        "required": [
          "product_id",
          "quantity",
          "unit_price_xof"
        ],
        "title": "TransactionItemInput",
        "description": "Single line item for amount calculation and loyalty context.\n\n## Why the snapshot fields exist here\n\n``product_name``, ``category_id`` and ``category_label`` are *not* used to\ncompute the amount. They are carried so the emitted\n``TransactionCreated.context.line_items[]`` matches ``CommerceLineItem/v1``,\nwhose contract calls them \"snapshot at sale time (not live catalog join)\".\n\nThat wording is the whole point. A product renamed, recategorised or\ndeleted next month must not rewrite what was sold last month. Reading the\ncatalogue at projection time would do exactly that — silently, and only\nfor the rows a merchant happened to edit.\n\nThey were missing, and the consequence was measurable rather than\ntheoretical: ``items_to_line_items`` already looks for these three keys,\nand ``product_sales.py`` already writes ``product_name_at_sale`` and\n``category_name_at_sale`` from them. But this schema had no field to put\nthem in, so Pydantic dropped whatever a client sent. Every merchant-app\nsale therefore projected with ``product_name = None`` and, worse,\n``bump_category_sales_day`` — guarded by ``if category_id is not None`` —\n**never ran at all**. Category revenue was structurally empty.\n\nAll three stay optional. A POS adapter that only knows a ``product_id`` is\nstill valid, and the projector's identifier cascade covers it."
      },
      "TransactionListResponse": {
        "properties": {
          "items": {
            "items": {
              "$ref": "#/components/schemas/TransactionResponse"
            },
            "type": "array",
            "title": "Items"
          },
          "next_cursor": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Next Cursor"
          }
        },
        "type": "object",
        "required": [
          "items"
        ],
        "title": "TransactionListResponse",
        "description": "Paginated list. next_cursor for next page."
      },
      "TransactionPreviewRequest": {
        "properties": {
          "customer_id": {
            "type": "string",
            "format": "uuid",
            "title": "Customer Id",
            "description": "Business customer id (persisted on ledger as customer_id)"
          },
          "loyalty_account_id": {
            "anyOf": [
              {
                "type": "string",
                "format": "uuid"
              },
              {
                "type": "null"
              }
            ],
            "title": "Loyalty Account Id",
            "description": "Loyalty program account id (canonical)."
          },
          "account_id": {
            "anyOf": [
              {
                "type": "string",
                "format": "uuid"
              },
              {
                "type": "null"
              }
            ],
            "title": "Account Id",
            "description": "DEPRECATED alias of loyalty_account_id (accepted temporarily for compat)."
          },
          "amount_xof": {
            "anyOf": [
              {
                "type": "integer",
                "maximum": 1000000000000000.0,
                "exclusiveMinimum": 0.0
              },
              {
                "type": "null"
              }
            ],
            "title": "Amount Xof",
            "description": "Total amount in whole XOF (when items not provided)"
          },
          "items": {
            "anyOf": [
              {
                "items": {
                  "$ref": "#/components/schemas/TransactionItemInput"
                },
                "type": "array",
                "maxItems": 500
              },
              {
                "type": "null"
              }
            ],
            "title": "Items",
            "description": "Line items; total = sum(quantity * unit_price_xof)"
          },
          "store_id": {
            "type": "string",
            "format": "uuid",
            "title": "Store Id",
            "description": "Store where the transaction is executed; must be listed in JWT store_ids (or org admin)"
          },
          "category_ids": {
            "anyOf": [
              {
                "items": {
                  "type": "string",
                  "format": "uuid"
                },
                "type": "array",
                "maxItems": 200
              },
              {
                "type": "null"
              }
            ],
            "title": "Category Ids",
            "description": "Optional category UUIDs forwarded to loyalty context.category_ids"
          },
          "redemption": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/RedemptionInput"
              },
              {
                "type": "null"
              }
            ],
            "description": "Optional: use points / select reward; forwarded to loyalty as context.redemption"
          },
          "gross_amount_xof": {
            "anyOf": [
              {
                "type": "integer",
                "maximum": 1000000000000000.0,
                "minimum": 0.0
              },
              {
                "type": "null"
              }
            ],
            "title": "Gross Amount Xof",
            "description": "Optional; sent to calculate-loyalty root gross_amount (align preview↔earn)"
          },
          "net_after_promotions_xof": {
            "anyOf": [
              {
                "type": "integer",
                "maximum": 1000000000000000.0,
                "minimum": 0.0
              },
              {
                "type": "null"
              }
            ],
            "title": "Net After Promotions Xof",
            "description": "Optional; sent to calculate-loyalty as net_after_promotions (base points engine)"
          },
          "net_after_rewards_xof": {
            "anyOf": [
              {
                "type": "integer",
                "maximum": 1000000000000000.0,
                "minimum": 0.0
              },
              {
                "type": "null"
              }
            ],
            "title": "Net After Rewards Xof",
            "description": "When set, used as root amount in calculate-loyalty (net payé); also sent as net_after_rewards"
          },
          "base_points_amount_xof": {
            "anyOf": [
              {
                "type": "integer",
                "maximum": 1000000000000000.0,
                "minimum": 0.0
              },
              {
                "type": "null"
              }
            ],
            "title": "Base Points Amount Xof",
            "description": "Optional; sent to calculate-loyalty as base_points_amount"
          }
        },
        "additionalProperties": false,
        "type": "object",
        "required": [
          "customer_id",
          "store_id"
        ],
        "title": "TransactionPreviewRequest",
        "description": "POST /transactions/preview body. Either amount or items must be provided."
      },
      "TransactionPreviewResponse": {
        "properties": {
          "status": {
            "type": "string",
            "title": "Status",
            "description": "OK | DEGRADED"
          },
          "loyalty_calculation_id": {
            "anyOf": [
              {
                "type": "string",
                "format": "uuid"
              },
              {
                "type": "null"
              }
            ],
            "title": "Loyalty Calculation Id",
            "description": "Correlation id for preview→confirm→Kafka; echo on confirm when status is OK"
          },
          "points_earned": {
            "anyOf": [
              {
                "type": "integer"
              },
              {
                "type": "null"
              }
            ],
            "title": "Points Earned"
          },
          "promotions": {
            "items": {
              "$ref": "#/components/schemas/PromotionPreviewItem"
            },
            "type": "array",
            "title": "Promotions"
          },
          "amount_breakdown": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/TransactionAmountBreakdownPreview"
              },
              {
                "type": "null"
              }
            ],
            "description": "Montants fidélité alignés calculate-loyalty (promotions + palier synthétique vs récompenses)."
          },
          "new_balance": {
            "anyOf": [
              {
                "type": "integer"
              },
              {
                "type": "null"
              }
            ],
            "title": "New Balance"
          },
          "warnings": {
            "items": {
              "type": "string"
            },
            "type": "array",
            "title": "Warnings"
          },
          "reward_offers": {
            "items": {
              "$ref": "#/components/schemas/RewardOfferItem"
            },
            "type": "array",
            "title": "Reward Offers"
          },
          "applied_rewards_preview": {
            "items": {
              "$ref": "#/components/schemas/AppliedRewardItem"
            },
            "type": "array",
            "title": "Applied Rewards Preview"
          },
          "points_redeemed": {
            "anyOf": [
              {
                "type": "integer"
              },
              {
                "type": "null"
              }
            ],
            "title": "Points Redeemed",
            "description": "Points that would be / were burned for this basket (loyalty; 0 if none)"
          },
          "points_redeemable_estimate": {
            "anyOf": [
              {
                "type": "integer"
              },
              {
                "type": "null"
              }
            ],
            "title": "Points Redeemable Estimate",
            "description": "Optional: max points usable on this transaction per loyalty rules"
          },
          "discount_from_rewards_estimate_xof": {
            "anyOf": [
              {
                "type": "integer"
              },
              {
                "type": "null"
              }
            ],
            "title": "Discount From Rewards Estimate Xof",
            "description": "Optional: monetary discount from rewards/redemption for this basket (whole XOF)"
          }
        },
        "type": "object",
        "required": [
          "status"
        ],
        "title": "TransactionPreviewResponse",
        "description": "Response for POST /transactions/preview. Always 200; status OK or DEGRADED."
      },
      "TransactionResponse": {
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "title": "Id"
          },
          "org_id": {
            "type": "string",
            "format": "uuid",
            "title": "Org Id"
          },
          "customer_id": {
            "type": "string",
            "format": "uuid",
            "title": "Customer Id"
          },
          "customer_display_name": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Customer Display Name",
            "description": "Resolved customer label (first_name last_name / email / 'Client'); None if name enrichment unavailable."
          },
          "loyalty_account_id": {
            "type": "string",
            "format": "uuid",
            "title": "Loyalty Account Id"
          },
          "type": {
            "type": "string",
            "title": "Type"
          },
          "points": {
            "type": "integer",
            "title": "Points"
          },
          "store_id": {
            "anyOf": [
              {
                "type": "string",
                "format": "uuid"
              },
              {
                "type": "null"
              }
            ],
            "title": "Store Id"
          },
          "monetary_amount_xof": {
            "anyOf": [
              {
                "type": "integer"
              },
              {
                "type": "null"
              }
            ],
            "title": "Monetary Amount Xof"
          },
          "currency": {
            "type": "string",
            "title": "Currency",
            "default": "XOF"
          },
          "reference_type": {
            "type": "string",
            "title": "Reference Type"
          },
          "reference_id": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Reference Id"
          },
          "metadata": {
            "additionalProperties": true,
            "type": "object",
            "title": "Metadata"
          },
          "created_by": {
            "anyOf": [
              {
                "type": "string",
                "format": "uuid"
              },
              {
                "type": "null"
              }
            ],
            "title": "Created By"
          },
          "created_at": {
            "anyOf": [
              {
                "type": "string",
                "format": "date-time"
              },
              {
                "type": "null"
              }
            ],
            "title": "Created At"
          },
          "occurred_at": {
            "anyOf": [
              {
                "type": "string",
                "format": "date-time"
              },
              {
                "type": "null"
              }
            ],
            "title": "Occurred At",
            "description": "Instant métier de la vente au comptoir. `created_at` est l'heure d'écriture au grand livre — les deux diffèrent de plusieurs jours pour une vente hors ligne. C'est `occurred_at` qui ordonne les listes et que l'interface affiche."
          },
          "reversal_of_id": {
            "anyOf": [
              {
                "type": "string",
                "format": "uuid"
              },
              {
                "type": "null"
              }
            ],
            "title": "Reversal Of Id"
          },
          "transaction_hash": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Transaction Hash"
          },
          "declared_collected_xof": {
            "anyOf": [
              {
                "type": "integer"
              },
              {
                "type": "null"
              }
            ],
            "title": "Declared Collected Xof",
            "description": "Fait de caisse : ce que le terminal déclare avoir encaissé. Jamais recalculé, jamais corrigé par le serveur."
          },
          "declared_discount_xof": {
            "anyOf": [
              {
                "type": "integer"
              },
              {
                "type": "null"
              }
            ],
            "title": "Declared Discount Xof",
            "description": "Fait de caisse : la remise que le terminal déclare avoir accordée."
          },
          "historical_eligible_discount_xof": {
            "anyOf": [
              {
                "type": "integer"
              },
              {
                "type": "null"
              }
            ],
            "title": "Historical Eligible Discount Xof",
            "description": "Droit calculé : la remise à laquelle la vente avait droit à son instant métier. À comparer à `declared_discount_xof` — un fait et un droit, jamais confondus."
          },
          "validation_verdict": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Validation Verdict",
            "description": "Rapprochement du fait et du droit, calculé à la confirmation : EXACT, UNDER_GRANTED, OVER_GRANTED, NOT_DECLARED, HISTORY_UNAVAILABLE. Un constat, jamais une correction : il ne modifie ni les points, ni les montants. `null` sur les ventes antérieures à la révision 018."
          },
          "loyalty_credit_state": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Loyalty Credit State",
            "description": "Ce que la **fidélité** a fait de cette vente. `points` ci-dessus est le résultat du calcul ; ce champ porte le crédit, et les deux peuvent diverger — une vente retenue par l'antifraude vaut ses points et n'en crédite aucun. `AWAITING` : annoncés, non encore confirmés. `CONFIRMED` : `service-loyalty` a confirmé le crédit. `null` sur les ventes antérieures à la révision 019, et ce null ne dit **ni** crédité **ni** retenu. Aucune interface ne doit présenter des points comme acquis sans `CONFIRMED`."
          },
          "loyalty_credited_points": {
            "anyOf": [
              {
                "type": "integer"
              },
              {
                "type": "null"
              }
            ],
            "title": "Loyalty Credited Points",
            "description": "Les points que `service-loyalty` déclare avoir crédités. `null` tant qu'elle n'a rien confirmé."
          }
        },
        "type": "object",
        "required": [
          "id",
          "org_id",
          "customer_id",
          "loyalty_account_id",
          "type",
          "points",
          "reference_type"
        ],
        "title": "TransactionResponse",
        "description": "Single transaction in API response."
      },
      "ValidationError": {
        "properties": {
          "loc": {
            "items": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "integer"
                }
              ]
            },
            "type": "array",
            "title": "Location"
          },
          "msg": {
            "type": "string",
            "title": "Message"
          },
          "type": {
            "type": "string",
            "title": "Error Type"
          }
        },
        "type": "object",
        "required": [
          "loc",
          "msg",
          "type"
        ],
        "title": "ValidationError"
      }
    }
  },
  "security": [
    {
      "ApiKeyAuth": []
    }
  ],
  "paths": {
    "/api/v1/external/pos/v1/sales/previews": {
      "post": {
        "tags": [
          "api",
          "pos-public-v1",
          "pos-public-v1"
        ],
        "summary": "Pos Post Sales Preview",
        "operationId": "pos_post_sales_preview_api_v1_external_pos_v1_sales_previews_post",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TransactionPreviewRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TransactionPreviewResponse"
                }
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/external/pos/v1/sales/confirmations": {
      "post": {
        "tags": [
          "api",
          "pos-public-v1",
          "pos-public-v1"
        ],
        "summary": "Pos Post Sales Confirmation",
        "description": "Requires ``pos:sales:write``; a ``redemption`` that spends points or a reward also requires\n``pos:sales:redeem`` (otherwise 403 ``MISSING_SCOPE_POS_SALES_REDEEM``, nothing written).",
        "operationId": "pos_post_sales_confirmation_api_v1_external_pos_v1_sales_confirmations_post",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ],
              "title": "Idempotency-Key"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TransactionConfirmRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TransactionConfirmResponse"
                }
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/external/pos/v1/sales/confirmations/batch": {
      "post": {
        "tags": [
          "api",
          "pos-public-v1",
          "pos-public-v1"
        ],
        "summary": "Pos Post Sales Confirmations Batch",
        "description": "Requires ``pos:sales:write``; an item whose ``redemption`` spends points or a reward also requires\n``pos:sales:redeem`` (otherwise that item alone fails with 403 ``MISSING_SCOPE_POS_SALES_REDEEM``).",
        "operationId": "pos_post_sales_confirmations_batch_api_v1_external_pos_v1_sales_confirmations_batch_post",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TransactionConfirmBatchRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TransactionConfirmBatchResponse"
                }
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/external/pos/v1/sales/idempotency-status": {
      "post": {
        "tags": [
          "api",
          "pos-public-v1",
          "pos-public-v1"
        ],
        "summary": "Pos Post Sales Idempotency Status",
        "description": "Requires ``pos:sales:read`` (same as preview). A key from another store reads as ``unknown``.",
        "operationId": "pos_post_sales_idempotency_status_api_v1_external_pos_v1_sales_idempotency_status_post",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/IdempotencyStatusRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/IdempotencyStatusResponse"
                }
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/external/transactions/v1/{transaction_id}": {
      "get": {
        "tags": [
          "api",
          "transactions-public-v1",
          "transactions-public-v1"
        ],
        "summary": "Get Transaction Public",
        "operationId": "get_transaction_public_api_v1_external_transactions_v1__transaction_id__get",
        "parameters": [
          {
            "name": "transaction_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid",
              "title": "Transaction Id"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TransactionResponse"
                }
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/external/transactions/v1": {
      "get": {
        "tags": [
          "api",
          "transactions-public-v1",
          "transactions-public-v1"
        ],
        "summary": "List Transactions Public",
        "operationId": "list_transactions_public_api_v1_external_transactions_v1_get",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "maximum": 100,
              "minimum": 1,
              "default": 20,
              "title": "Limit"
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "schema": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ],
              "title": "Cursor"
            }
          },
          {
            "name": "store_id",
            "in": "query",
            "required": false,
            "schema": {
              "anyOf": [
                {
                  "type": "string",
                  "format": "uuid"
                },
                {
                  "type": "null"
                }
              ],
              "description": "Optional store filter (must be in JWT store_ids)",
              "title": "Store Id"
            },
            "description": "Optional store filter (must be in JWT store_ids)"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TransactionListResponse"
                }
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      }
    }
  }
}
