{
  "openapi": "3.0.3",
  "info": {
    "title": "SAMA sarie & mada Central Payment Switch API",
    "version": "2.0.0",
    "description": "\n# 🇸🇦 Saudi Central Bank (SAMA) Central Payment Switch\n**National Digital Financial Infrastructure Simulation (sarie • mada • SADAD • Nafath)**\n\n---\n\n### Key Capabilities:\n- ⚡ **sarie (سريع)**: Sub-3-second Instant P2P and Commercial interbank payments.\n- 💳 **mada (مدى)**: POS card and dynamic QR retail payment acceptance.\n- 🧾 **SADAD (سداد)**: National electronic bill presentment and payment system.\n- 🆔 **Nafath (نفاذ)**: National Unified Digital Identity & Saudi eKYC simulation.\n- 🏢 **Merchant Platform**: 13 comprehensive enterprise modules covering onboarding, instant settlements (**SettleNow**), ZATCA Phase 2 digital receipts, remote payment links, and AI payment chatbot.\n- 🏦 **Multi-Bank Architecture**: Connected to 10+ Saudi commercial banks (SNB, Al Rajhi, Riyad Bank, Alinma, SAB, BSF, ANB, Bank AlBilad, Bank AlJazira, GIB).\n- 🗄️ **High-Performance RDS PostgreSQL**: ACID-compliant transactional persistence on AWS RDS PostgreSQL.\n\n---\n\n### Authentication Schemes:\n1. **Merchant API Key**: Pass `X-API-KEY: key_live_...` in request headers.\n2. **Merchant ID Context**: Pass `X-Merchant-ID: MERCH_TAMIMI_KSA` or query parameter `?merchantId=...`.\n3. **Consumer User Session**: Pass `Authorization: Bearer <sessionToken>` or standard OTP/PIN verification.\n      ",
    "contact": {
      "name": "SAMA Payment Switch Engineering",
      "url": "https://sama.gov.sa"
    },
    "license": {
      "name": "SAMA National Payment Systems Regulations",
      "url": "https://sama.gov.sa"
    }
  },
  "servers": [
    {
      "url": "https://switch.cloud.quantiratechnologies.com",
      "description": "Active SAMA Switch Instance (PostgreSQL on AWS RDS)"
    }
  ],
  "tags": [
    {
      "name": "System & Metadata",
      "description": "Switch operational status, SLA metrics, and participant bank directories"
    },
    {
      "name": "Consumer Users & Onboarding",
      "description": "National identity onboarding, account discovery, and IBAN linking"
    },
    {
      "name": "Nafath National eKYC",
      "description": "Nafath 2-digit verification protocol and identity authorization"
    },
    {
      "name": "sarie Instant Payments (P2P)",
      "description": "Real-time peer-to-peer interbank transfers via IBAN or mobile alias"
    },
    {
      "name": "mada QR Payments (P2M)",
      "description": "Merchant retail payments via static or dynamic mada QR"
    },
    {
      "name": "Settlements & SettleNow (M2B)",
      "description": "Escrow sweeps and real-time bank account payout execution"
    },
    {
      "name": "SADAD Electronic Invoicing",
      "description": "National utility, government, and commercial bill inquiry and payment"
    },
    {
      "name": "QR Code Engine",
      "description": "SAMA sarie and mada QR payload generation, parsing, and validation"
    },
    {
      "name": "Notifications & Dual-Party Stream",
      "description": "Server-Sent Events (SSE) and dual-party push notification dispatch"
    },
    {
      "name": "Merchant: Registration & Onboarding",
      "description": "CR 10-digit validation, ZATCA 15-digit VAT, and onboarding status"
    },
    {
      "name": "Merchant: Dashboard & Analytics",
      "description": "Live sales metrics, collections breakdown, and business overview"
    },
    {
      "name": "Merchant: QR Acceptance",
      "description": "Counter static QRs, dynamic order QRs, and in-store payment collection"
    },
    {
      "name": "Merchant: Transactions & Receipts",
      "description": "Transaction history, search, and ZATCA Phase 2 digital receipts"
    },
    {
      "name": "Merchant: Settlements & SettleNow",
      "description": "Daily settlement logs, pending balances, and instant SettleNow sweeps"
    },
    {
      "name": "Merchant: Refunds & Disputes",
      "description": "ISO 20022 pacs.004 refunds, customer disputes, and dispute resolution"
    },
    {
      "name": "Merchant: Bank Account Management",
      "description": "Linked settlement Saudi IBANs, sarie verification, and primary routing"
    },
    {
      "name": "Merchant: Remote Payment Links",
      "description": "Digital payment links, public checkout URLs, and mobile PIN payment"
    },
    {
      "name": "Merchant: Business Reports",
      "description": "Sales, settlement, and daily SAMA reconciliation reports with CSV/JSON export"
    },
    {
      "name": "Merchant: Store Management",
      "description": "Business profile, physical branch locations, and mada POS terminal IDs"
    },
    {
      "name": "Merchant: Help & Support",
      "description": "Support tickets, message threads, and intelligent payment chatbot"
    },
    {
      "name": "Merchant: Settings & Security",
      "description": "Immediate settlement toggles, API keys regeneration, and PIN security"
    },
    {
      "name": "Merchant: Team & Permissions",
      "description": "Staff members, access roles, and granular operational permissions"
    },
    {
      "name": "Demo Environment & Testing",
      "description": "10 Pre-configured Saudi merchants, 10 test users, and database reset"
    }
  ],
  "paths": {
    "/api/v1/health": {
      "get": {
        "tags": [
          "System & Metadata"
        ],
        "summary": "Check Switch Operational Health & SAMA SLA",
        "description": "Returns real-time operational status, database statistics, participant banks count, and SLA compliance metrics.",
        "responses": {
          "200": {
            "description": "Switch is healthy and operational",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HealthResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/meta/banks": {
      "get": {
        "tags": [
          "System & Metadata"
        ],
        "summary": "List Participant Saudi Commercial Banks",
        "description": "Returns the catalog of 12 Saudi banks participating in sarie and mada, with routing codes, BIC, and bilingual names.",
        "responses": {
          "200": {
            "description": "List of participant banks",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BanksResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/meta/mcc": {
      "get": {
        "tags": [
          "System & Metadata"
        ],
        "summary": "List Merchant Category Codes (MCC)",
        "description": "Returns the standard SAMA MCC catalog (Retail, Grocery, Dining, Healthcare, Electronics, etc.).",
        "responses": {
          "200": {
            "description": "MCC Catalog"
          }
        }
      }
    },
    "/api/v1/meta/sadad/billers": {
      "get": {
        "tags": [
          "System & Metadata"
        ],
        "summary": "List SADAD Electronic Billers",
        "description": "Returns the directory of SADAD billers (Telecom, Electricity, Water, MOI Government Services).",
        "responses": {
          "200": {
            "description": "SADAD Billers list"
          }
        }
      }
    },
    "/api/v1/users/register": {
      "post": {
        "tags": [
          "Consumer Users & Onboarding"
        ],
        "summary": "Register Consumer User (National ID / Iqama)",
        "description": "Registers a new user into the SAMA directory with Absher/Nafath identity, mobile number, and cryptographic device fingerprint.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UserRegisterRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "User registered successfully"
          },
          "400": {
            "description": "Validation error"
          }
        }
      }
    },
    "/api/v1/auth/login": {
      "post": {
        "tags": [
          "Consumer Users & Onboarding"
        ],
        "summary": "User Login with PIN or Password",
        "description": "Authenticates a user via mobile number and 6-digit PIN or password.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "mobileNumber"
                ],
                "properties": {
                  "mobileNumber": {
                    "type": "string",
                    "example": "0501234567"
                  },
                  "pin": {
                    "type": "string",
                    "example": "123456"
                  },
                  "password": {
                    "type": "string",
                    "example": "123456"
                  },
                  "otpCode": {
                    "type": "string",
                    "example": "1234"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Login successful"
          },
          "400": {
            "description": "Invalid credentials"
          }
        }
      }
    },
    "/api/v1/users/me": {
      "get": {
        "tags": [
          "Consumer Users & Onboarding"
        ],
        "summary": "Get Authenticated User Profile & Accounts",
        "responses": {
          "200": {
            "description": "User profile with linked accounts"
          }
        }
      }
    },
    "/api/v1/users/accounts/discover": {
      "post": {
        "tags": [
          "Consumer Users & Onboarding"
        ],
        "summary": "Discover Bank Accounts across Saudi Banks",
        "description": "Simulates SAMA Open Banking account discovery across participant Saudi banks for the user National ID.",
        "responses": {
          "200": {
            "description": "Discovered bank accounts"
          }
        }
      }
    },
    "/api/v1/users/accounts/link": {
      "post": {
        "tags": [
          "Consumer Users & Onboarding"
        ],
        "summary": "Link Bank Account to sarie Mobile Alias",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "accountId": {
                    "type": "string",
                    "example": "ACC_001"
                  },
                  "iban": {
                    "type": "string",
                    "example": "SA0310000001099887766554"
                  },
                  "customSarieAlias": {
                    "type": "string",
                    "example": "0501234567"
                  },
                  "pin": {
                    "type": "string",
                    "example": "123456"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Account linked successfully"
          }
        }
      }
    },
    "/api/v1/users/accounts/primary": {
      "put": {
        "tags": [
          "Consumer Users & Onboarding"
        ],
        "summary": "Set the authenticated user primary bank account",
        "description": "Selects an active bank account already linked to the authenticated user. The selection remains primary until explicitly changed.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "accountId": {
                    "type": "string",
                    "example": "ACC_001"
                  },
                  "iban": {
                    "type": "string",
                    "example": "SA0310000001099887766554"
                  }
                },
                "oneOf": [
                  {
                    "required": [
                      "accountId"
                    ]
                  },
                  {
                    "required": [
                      "iban"
                    ]
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Primary account updated"
          },
          "400": {
            "description": "Invalid primary account request"
          },
          "404": {
            "description": "Active linked account not found"
          }
        }
      }
    },
    "/api/v1/auth/nafath/initiate": {
      "post": {
        "tags": [
          "Nafath National eKYC"
        ],
        "summary": "Initiate Nafath National Authentication",
        "description": "Generates a 2-digit verification prompt code for the citizen or resident to select in the Nafath mobile app.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "nationalId"
                ],
                "properties": {
                  "nationalId": {
                    "type": "string",
                    "example": "1098765432"
                  },
                  "mobileNumber": {
                    "type": "string",
                    "example": "0501234567"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Nafath request initiated with 2-digit code"
          }
        }
      }
    },
    "/api/v1/auth/nafath/status/{requestId}": {
      "get": {
        "tags": [
          "Nafath National eKYC"
        ],
        "summary": "Poll Nafath Request Approval Status",
        "parameters": [
          {
            "name": "requestId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "example": "NFTH_1A2B3C"
          }
        ],
        "responses": {
          "200": {
            "description": "Current Nafath approval state"
          }
        }
      }
    },
    "/api/v1/auth/nafath/approve": {
      "post": {
        "tags": [
          "Nafath National eKYC"
        ],
        "summary": "Approve Nafath Request (App Simulation)",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "requestId",
                  "selectedCode"
                ],
                "properties": {
                  "requestId": {
                    "type": "string",
                    "example": "NFTH_1A2B3C"
                  },
                  "selectedCode": {
                    "type": "integer",
                    "example": 42
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Nafath approval completed"
          }
        }
      }
    },
    "/api/v1/payments/p2p": {
      "post": {
        "tags": [
          "sarie Instant Payments (P2P)"
        ],
        "summary": "Execute Instant P2P Payment (sarie IPS)",
        "description": "Executes an instant interbank transfer under SAMA rules. Supports routing by IBAN or mobile alias. Settlement completes in <2 seconds.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/P2PPaymentRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Payment successful",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TransactionResponse"
                }
              }
            }
          },
          "400": {
            "description": "Payment declined (insufficient funds, invalid PIN, limits)"
          }
        }
      }
    },
    "/api/v1/payments/p2m": {
      "post": {
        "tags": [
          "mada QR Payments (P2M)"
        ],
        "summary": "Process mada QR Retail Payment",
        "description": "Processes a customer-to-merchant payment by scanning a static or dynamic mada QR code. Funds are instantly settled to the merchant bank account.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "qrPayload",
                  "pin"
                ],
                "properties": {
                  "remitterMobile": {
                    "type": "string",
                    "example": "0501234567"
                  },
                  "remitterIban": {
                    "type": "string",
                    "example": "SA0310000001099887766554"
                  },
                  "qrPayload": {
                    "type": "string",
                    "example": "sarie://pay?iban=SA0310000009999000011101&pn=Tamimi%20Markets&mc=5411"
                  },
                  "amount": {
                    "type": "number",
                    "example": 125.5
                  },
                  "pin": {
                    "type": "string",
                    "example": "123456"
                  },
                  "note": {
                    "type": "string",
                    "example": "Grocery shopping"
                  },
                  "autoSettle": {
                    "type": "boolean",
                    "default": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "mada payment processed"
          },
          "400": {
            "description": "Payment failed"
          }
        }
      }
    },
    "/api/v1/payments/m2b/settle": {
      "post": {
        "tags": [
          "Settlements & CBS (M2B)"
        ],
        "summary": "Execute On-Demand Merchant Settlement Payout",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "merchantId"
                ],
                "properties": {
                  "merchantId": {
                    "type": "string",
                    "example": "MERCH_TAMIMI_KSA"
                  },
                  "amount": {
                    "type": "number",
                    "example": 500
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Settlement payout executed"
          }
        }
      }
    },
    "/api/v1/payments/settlements/batch": {
      "post": {
        "tags": [
          "Settlements & CBS (M2B)"
        ],
        "summary": "Trigger Automated Multi-Merchant Batch Settlement",
        "responses": {
          "200": {
            "description": "Batch settlement executed for all merchants"
          }
        }
      }
    },
    "/api/v1/payments/sadad/inquire": {
      "post": {
        "tags": [
          "SADAD Electronic Invoicing"
        ],
        "summary": "Inquire SADAD Electronic Bill",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "billerCode"
                ],
                "properties": {
                  "billerCode": {
                    "type": "string",
                    "example": "001"
                  },
                  "billNumber": {
                    "type": "string",
                    "example": "BILL_001_998877"
                  },
                  "subscriberNumber": {
                    "type": "string",
                    "example": "1098765432"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Bill details and due amount in SAR"
          }
        }
      }
    },
    "/api/v1/payments/sadad/pay": {
      "post": {
        "tags": [
          "SADAD Electronic Invoicing"
        ],
        "summary": "Pay SADAD Electronic Bill",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "billNumber",
                  "amount",
                  "pin"
                ],
                "properties": {
                  "billNumber": {
                    "type": "string",
                    "example": "BILL_001_998877"
                  },
                  "remitterMobile": {
                    "type": "string",
                    "example": "0501234567"
                  },
                  "amount": {
                    "type": "number",
                    "example": 320
                  },
                  "pin": {
                    "type": "string",
                    "example": "123456"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "SADAD bill paid successfully"
          }
        }
      }
    },
    "/api/v1/qr/generate": {
      "post": {
        "tags": [
          "QR Code Engine"
        ],
        "summary": "Generate SAMA EMVCo / sarie QR Code",
        "description": "Generates standard SAMA compliant QR URI payload, SVG vector, and base64 PNG data URL.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "iban": {
                    "type": "string",
                    "example": "SA0310000001099887766554"
                  },
                  "payeeName": {
                    "type": "string",
                    "example": "Tariq Al-Harbi"
                  },
                  "amount": {
                    "type": "number",
                    "example": 150
                  },
                  "mobileNumber": {
                    "type": "string",
                    "example": "0501234567"
                  },
                  "note": {
                    "type": "string",
                    "example": "Dinner share"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "QR code generated with SVG and URI"
          }
        }
      }
    },
    "/api/v1/qr/parse": {
      "post": {
        "tags": [
          "QR Code Engine"
        ],
        "summary": "Parse & Disambiguate QR Code Payload",
        "description": "Parses QR payload to automatically determine whether it is a Personal sarie P2P QR or a mada Retail Merchant QR.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "qrPayload"
                ],
                "properties": {
                  "qrPayload": {
                    "type": "string",
                    "example": "sarie://pay?iban=SA0310000001099887766554&pn=Tariq%20Al-Harbi&mobile=0501234567&cu=SAR"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Parsed QR metadata with scheme classification"
          }
        }
      }
    },
    "/api/v1/qr/p2p/user/{userId}": {
      "get": {
        "tags": [
          "QR Code Engine"
        ],
        "summary": "Get Personal sarie P2P QR for Database User",
        "parameters": [
          {
            "name": "userId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "example": "0501234567"
          }
        ],
        "responses": {
          "200": {
            "description": "User personal P2P QR payload and SVG"
          }
        }
      }
    },
    "/api/v1/notifications/stream": {
      "get": {
        "tags": [
          "Notifications & Dual-Party Stream"
        ],
        "summary": "Server-Sent Events (SSE) Live Push Stream",
        "description": "Streams instant real-time payment alerts, dual-party details, and updated bank balances to remitter and beneficiary apps.",
        "parameters": [
          {
            "name": "identifier",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "example": "0501234567"
          }
        ],
        "responses": {
          "200": {
            "description": "SSE event stream (text/event-stream)",
            "content": {
              "text/event-stream": {}
            }
          }
        }
      }
    },
    "/api/v1/notifications/push": {
      "post": {
        "tags": [
          "Notifications & Dual-Party Stream"
        ],
        "summary": "Dispatch Dual-Party Transaction Notification",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "reference"
                ],
                "properties": {
                  "reference": {
                    "type": "string",
                    "example": "628114062639"
                  },
                  "remitterMobile": {
                    "type": "string",
                    "example": "0501234567"
                  },
                  "beneficiaryMobile": {
                    "type": "string",
                    "example": "0502345678"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Notification dispatched to both parties"
          }
        }
      }
    },
    "/api/v1/notifications/transaction/{reference}": {
      "get": {
        "tags": [
          "Notifications & Dual-Party Stream"
        ],
        "summary": "Get Dual-Party Transaction Details & SAMA Naming",
        "description": "Strictly enforces SAMA rule: Remitter sees Beneficiary Name, and Beneficiary sees Remitter Name.",
        "parameters": [
          {
            "name": "reference",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "example": "628114062639"
          }
        ],
        "responses": {
          "200": {
            "description": "Dual-party details"
          }
        }
      }
    },
    "/api/v1/merchant/login": {
      "post": {
        "tags": [
          "Merchant: Registration & Onboarding"
        ],
        "summary": "Merchant Login (Public - Returns Session & LocalStorage Credentials)",
        "description": "Authenticates a merchant WITHOUT requiring Authorization, X-API-KEY, X-Signature, or Idempotency-Key headers in the request. Returns complete credentials (Bearer JWT token, X-API-KEY, apiSecret, sample X-Signature, and Idempotency-Key) structured for direct localStorage storage and subsequent requests.",
        "security": [],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "merchantId": {
                    "type": "string",
                    "example": "MERCH_TAMIMI_KSA",
                    "description": "Merchant ID (optional if mobile/email/apiKey passed)"
                  },
                  "mobileNumber": {
                    "type": "string",
                    "example": "0509999001",
                    "description": "Registered Saudi mobile number"
                  },
                  "email": {
                    "type": "string",
                    "example": "finance@tamimi.com.sa",
                    "description": "Merchant business email"
                  },
                  "apiKey": {
                    "type": "string",
                    "example": "key_live_...",
                    "description": "Merchant API Key"
                  },
                  "password": {
                    "type": "string",
                    "example": "123456",
                    "description": "Merchant login password (default: 123456)"
                  },
                  "pin": {
                    "type": "string",
                    "example": "123456",
                    "description": "Merchant transaction PIN (default: 123456)"
                  },
                  "otpCode": {
                    "type": "string",
                    "example": "123456",
                    "description": "OTP code for SMS 2FA"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Merchant login successful with complete security credentials for localStorage",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    },
                    "messageEn": {
                      "type": "string",
                      "example": "Merchant logged in successfully"
                    },
                    "messageAr": {
                      "type": "string",
                      "example": "تم تسجيل دخول التاجر بنجاح"
                    },
                    "token": {
                      "type": "string",
                      "example": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
                    },
                    "authorization": {
                      "type": "string",
                      "example": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
                    },
                    "apiKey": {
                      "type": "string",
                      "example": "key_live_a1b2c3d4e5f67890"
                    },
                    "xApiKey": {
                      "type": "string",
                      "example": "key_live_a1b2c3d4e5f67890"
                    },
                    "apiSecret": {
                      "type": "string",
                      "example": "sec_7f8a9b0c1d2e3f4a5b6c"
                    },
                    "signatureSecret": {
                      "type": "string",
                      "example": "sec_7f8a9b0c1d2e3f4a5b6c"
                    },
                    "xSignature": {
                      "type": "string",
                      "example": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
                    },
                    "idempotencyKey": {
                      "type": "string",
                      "example": "IDEMP_1712589000000_A1B2C3"
                    },
                    "headers": {
                      "type": "object",
                      "description": "Ready-to-use HTTP headers for subsequent requests",
                      "properties": {
                        "Authorization": {
                          "type": "string",
                          "example": "Bearer eyJhbGciOi..."
                        },
                        "X-API-KEY": {
                          "type": "string",
                          "example": "key_live_..."
                        },
                        "X-Signature": {
                          "type": "string",
                          "example": "e3b0c44..."
                        },
                        "Idempotency-Key": {
                          "type": "string",
                          "example": "IDEMP_..."
                        },
                        "X-Merchant-ID": {
                          "type": "string",
                          "example": "MERCH_TAMIMI_KSA"
                        }
                      }
                    },
                    "localStorage": {
                      "type": "object",
                      "description": "Pre-formatted dictionary ready for localStorage storage"
                    },
                    "merchant": {
                      "type": "object",
                      "description": "Full Saudi Merchant Profile"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid merchant credentials"
          }
        }
      }
    },
    "/api/v1/merchants/login": {
      "post": {
        "tags": [
          "Merchant: Registration & Onboarding"
        ],
        "summary": "Merchant Login Alias",
        "description": "Alias for /api/v1/merchant/login. Authenticates without requiring Authorization, X-API-KEY, X-Signature, or Idempotency-Key headers in request.",
        "security": [],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "merchantId": {
                    "type": "string",
                    "example": "MERCH_TAMIMI_KSA"
                  },
                  "password": {
                    "type": "string",
                    "example": "123456"
                  },
                  "pin": {
                    "type": "string",
                    "example": "123456"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Merchant login successful"
          }
        }
      }
    },
    "/api/v1/merchant/onboarding/register": {
      "post": {
        "tags": [
          "Merchant: Registration & Onboarding"
        ],
        "summary": "Register & Onboard New Saudi Merchant",
        "description": "Registers commercial enterprise, provisions primary store branch, links primary settlement bank account, and generates mada QR credentials.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/MerchantRegisterRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Merchant registered and activated"
          }
        }
      }
    },
    "/api/v1/merchant/onboarding/verify-cr": {
      "post": {
        "tags": [
          "Merchant: Registration & Onboarding"
        ],
        "summary": "Verify Ministry of Commerce CR (السجل التجاري)",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "crNumber"
                ],
                "properties": {
                  "crNumber": {
                    "type": "string",
                    "example": "1010223344"
                  },
                  "tradeName": {
                    "type": "string",
                    "example": "Tamimi Markets"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "CR verified with Ministry of Commerce"
          }
        }
      }
    },
    "/api/v1/merchant/onboarding/verify-vat": {
      "post": {
        "tags": [
          "Merchant: Registration & Onboarding"
        ],
        "summary": "Verify ZATCA 15-Digit VAT Tax Number (الرقم الضريبي)",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "vatNumber"
                ],
                "properties": {
                  "vatNumber": {
                    "type": "string",
                    "example": "300055443300003"
                  },
                  "crNumber": {
                    "type": "string",
                    "example": "1010223344"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "ZATCA VAT status active and compliant"
          }
        }
      }
    },
    "/api/v1/merchant/onboarding/verify-identity": {
      "post": {
        "tags": [
          "Merchant: Registration & Onboarding"
        ],
        "summary": "Verify Merchant Owner Identity via Nafath (نفاذ)",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "nationalId",
                  "mobileNumber"
                ],
                "properties": {
                  "nationalId": {
                    "type": "string",
                    "example": "1098765432"
                  },
                  "mobileNumber": {
                    "type": "string",
                    "example": "0599112233"
                  },
                  "merchantId": {
                    "type": "string",
                    "example": "MERCH_TAMIMI_KSA"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Owner identity verified"
          }
        }
      }
    },
    "/api/v1/merchant/onboarding/{merchantId}/status": {
      "get": {
        "tags": [
          "Merchant: Registration & Onboarding"
        ],
        "summary": "Get 8-Step Onboarding Progress Checklist",
        "parameters": [
          {
            "name": "merchantId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "example": "MERCH_TAMIMI_KSA"
          }
        ],
        "responses": {
          "200": {
            "description": "Onboarding checklist and completion percentage"
          }
        }
      }
    },
    "/api/v1/merchant/dashboard/overview": {
      "get": {
        "tags": [
          "Merchant: Dashboard & Analytics"
        ],
        "summary": "Get Merchant Comprehensive Dashboard Overview",
        "description": "Calculates real-time sales volume, net collections, live CBS bank balance, unsettled escrow balance in SAR, 7-day trend, and channel breakdown.",
        "parameters": [
          {
            "name": "merchantId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "example": "MERCH_TAMIMI_KSA"
          }
        ],
        "responses": {
          "200": {
            "description": "Executive dashboard summary"
          }
        }
      }
    },
    "/api/v1/merchant/qr/static": {
      "post": {
        "tags": [
          "Merchant: QR Acceptance"
        ],
        "summary": "Generate Counter Static mada QR",
        "parameters": [
          {
            "name": "merchantId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "example": "MERCH_TAMIMI_KSA"
          }
        ],
        "responses": {
          "200": {
            "description": "Static QR code payload and SVG"
          }
        }
      }
    },
    "/api/v1/merchant/qr/dynamic": {
      "post": {
        "tags": [
          "Merchant: QR Acceptance"
        ],
        "summary": "Generate Dynamic mada QR with Fixed Amount & Order Ref",
        "parameters": [
          {
            "name": "merchantId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "example": "MERCH_TAMIMI_KSA"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "amount"
                ],
                "properties": {
                  "amount": {
                    "type": "number",
                    "example": 350
                  },
                  "invoiceRef": {
                    "type": "string",
                    "example": "INV_TEST_350"
                  },
                  "note": {
                    "type": "string",
                    "example": "Fresh Organic Produce"
                  },
                  "expiryMinutes": {
                    "type": "integer",
                    "default": 30
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Dynamic QR generated"
          }
        }
      }
    },
    "/api/v1/merchant/qr/list": {
      "get": {
        "tags": [
          "Merchant: QR Acceptance"
        ],
        "summary": "List Merchant QR Codes",
        "parameters": [
          {
            "name": "merchantId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "example": "MERCH_TAMIMI_KSA"
          }
        ],
        "responses": {
          "200": {
            "description": "List of generated QR codes"
          }
        }
      }
    },
    "/api/v1/merchant/qr/collect": {
      "post": {
        "tags": [
          "Merchant: QR Acceptance"
        ],
        "summary": "Collect In-Store Payment against QR Code",
        "parameters": [
          {
            "name": "merchantId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "example": "MERCH_TAMIMI_KSA"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "customerMobile",
                  "qrPayload",
                  "pin"
                ],
                "properties": {
                  "customerMobile": {
                    "type": "string",
                    "example": "0501234567"
                  },
                  "qrPayload": {
                    "type": "string"
                  },
                  "pin": {
                    "type": "string",
                    "example": "123456"
                  },
                  "note": {
                    "type": "string",
                    "example": "Customer in-store QR scan"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Payment collected successfully"
          }
        }
      }
    },
    "/api/v1/merchant/transactions": {
      "get": {
        "tags": [
          "Merchant: Transactions & Receipts"
        ],
        "summary": "List Merchant Transactions",
        "parameters": [
          {
            "name": "merchantId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "example": "MERCH_TAMIMI_KSA"
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "ALL",
                "SUCCESS",
                "FAILED"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Paginated transactions list"
          }
        }
      }
    },
    "/api/v1/merchant/transactions/search": {
      "post": {
        "tags": [
          "Merchant: Transactions & Receipts"
        ],
        "summary": "Multi-Criteria Transaction Search",
        "parameters": [
          {
            "name": "merchantId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "example": "MERCH_TAMIMI_KSA"
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "rrn": {
                    "type": "string"
                  },
                  "utr": {
                    "type": "string"
                  },
                  "mobile": {
                    "type": "string"
                  },
                  "minAmount": {
                    "type": "number"
                  },
                  "maxAmount": {
                    "type": "number"
                  },
                  "status": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Matching transactions"
          }
        }
      }
    },
    "/api/v1/merchant/transactions/{reference}/receipt": {
      "get": {
        "tags": [
          "Merchant: Transactions & Receipts"
        ],
        "summary": "Generate ZATCA Phase 2 Compliant Digital Tax Invoice",
        "description": "Generates simplified electronic tax invoice with 15% VAT calculation, encrypted signature, seller CR, and buyer reference.",
        "parameters": [
          {
            "name": "reference",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "example": "628114062639"
          },
          {
            "name": "merchantId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "example": "MERCH_TAMIMI_KSA"
          }
        ],
        "responses": {
          "200": {
            "description": "ZATCA Tax Invoice"
          }
        }
      }
    },
    "/api/v1/merchant/settlements/summary": {
      "get": {
        "tags": [
          "Merchant: Settlements & SettleNow"
        ],
        "summary": "Get Settlement Escrow Summary",
        "parameters": [
          {
            "name": "merchantId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "example": "MERCH_TAMIMI_KSA"
          }
        ],
        "responses": {
          "200": {
            "description": "Summary of pending escrow and settled volumes"
          }
        }
      }
    },
    "/api/v1/merchant/settlements/settle-now": {
      "post": {
        "tags": [
          "Merchant: Settlements & SettleNow"
        ],
        "summary": "Execute SettleNow Instant Bank Payout",
        "description": "Instantly sweeps unsettled escrow balances into the verified Saudi settlement IBAN.",
        "parameters": [
          {
            "name": "merchantId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "example": "MERCH_TAMIMI_KSA"
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "amount": {
                    "type": "number",
                    "example": 200
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "SettleNow payout executed"
          }
        }
      }
    },
    "/api/v1/merchant/settlements": {
      "get": {
        "tags": [
          "Merchant: Settlements & SettleNow"
        ],
        "summary": "List Settlement Payout History",
        "parameters": [
          {
            "name": "merchantId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "example": "MERCH_TAMIMI_KSA"
          }
        ],
        "responses": {
          "200": {
            "description": "Settlement records"
          }
        }
      }
    },
    "/api/v1/merchant/refunds": {
      "post": {
        "tags": [
          "Merchant: Refunds & Disputes"
        ],
        "summary": "Process Merchant Refund (ISO 20022 pacs.004)",
        "parameters": [
          {
            "name": "merchantId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "example": "MERCH_TAMIMI_KSA"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "originalRrn",
                  "refundAmount"
                ],
                "properties": {
                  "originalRrn": {
                    "type": "string",
                    "example": "628114062639"
                  },
                  "refundAmount": {
                    "type": "number",
                    "example": 50
                  },
                  "refundReason": {
                    "type": "string",
                    "example": "Customer return / إرجاع منتج"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Refund executed successfully"
          }
        }
      },
      "get": {
        "tags": [
          "Merchant: Refunds & Disputes"
        ],
        "summary": "List Processed Refunds",
        "parameters": [
          {
            "name": "merchantId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "example": "MERCH_TAMIMI_KSA"
          }
        ],
        "responses": {
          "200": {
            "description": "Refunds history"
          }
        }
      }
    },
    "/api/v1/merchant/disputes": {
      "post": {
        "tags": [
          "Merchant: Refunds & Disputes"
        ],
        "summary": "Raise Customer Dispute for SAMA Investigation",
        "parameters": [
          {
            "name": "merchantId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "example": "MERCH_TAMIMI_KSA"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "txnReference",
                  "amount",
                  "reason"
                ],
                "properties": {
                  "txnReference": {
                    "type": "string",
                    "example": "628114062639"
                  },
                  "customerMobile": {
                    "type": "string",
                    "example": "0501234567"
                  },
                  "amount": {
                    "type": "number",
                    "example": 300
                  },
                  "reason": {
                    "type": "string",
                    "example": "DUPLICATE_CHARGE"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Dispute submitted to SAMA mediation queue"
          }
        }
      },
      "get": {
        "tags": [
          "Merchant: Refunds & Disputes"
        ],
        "summary": "List Merchant Disputes",
        "parameters": [
          {
            "name": "merchantId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "example": "MERCH_TAMIMI_KSA"
          }
        ],
        "responses": {
          "200": {
            "description": "Disputes list"
          }
        }
      }
    },
    "/api/v1/merchant/disputes/{disputeId}/resolve": {
      "post": {
        "tags": [
          "Merchant: Refunds & Disputes"
        ],
        "summary": "Resolve Dispute with Resolution Note",
        "parameters": [
          {
            "name": "disputeId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "example": "DISP_1A2B3C"
          },
          {
            "name": "merchantId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "example": "MERCH_TAMIMI_KSA"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "resolutionStatus": {
                    "type": "string",
                    "example": "RESOLVED_REFUNDED"
                  },
                  "resolutionNote": {
                    "type": "string",
                    "example": "Merchant reviewed POS logs and processed credit"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Dispute resolved"
          }
        }
      }
    },
    "/api/v1/merchant/bank-accounts": {
      "get": {
        "tags": [
          "Merchant: Bank Account Management"
        ],
        "summary": "List Linked Saudi Settlement Accounts",
        "parameters": [
          {
            "name": "merchantId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "example": "MERCH_TAMIMI_KSA"
          }
        ],
        "responses": {
          "200": {
            "description": "List of linked accounts"
          }
        }
      },
      "post": {
        "tags": [
          "Merchant: Bank Account Management"
        ],
        "summary": "Link New Settlement Saudi IBAN",
        "parameters": [
          {
            "name": "merchantId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "example": "MERCH_TAMIMI_KSA"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "iban"
                ],
                "properties": {
                  "iban": {
                    "type": "string",
                    "example": "SA0380000009999000099999"
                  },
                  "bankCode": {
                    "type": "string",
                    "example": "RJHI"
                  },
                  "isPrimary": {
                    "type": "boolean",
                    "default": false
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Bank account linked"
          }
        }
      }
    },
    "/api/v1/merchant/bank-accounts/{accountId}": {
      "delete": {
        "tags": [
          "Merchant: Bank Account Management"
        ],
        "summary": "Unlink Secondary Bank Account",
        "parameters": [
          {
            "name": "accountId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "example": "MBANK_1A2B"
          },
          {
            "name": "merchantId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "example": "MERCH_TAMIMI_KSA"
          }
        ],
        "responses": {
          "200": {
            "description": "Bank account unlinked"
          }
        }
      }
    },
    "/api/v1/merchant/bank-accounts/{accountId}/primary": {
      "put": {
        "tags": [
          "Merchant: Bank Account Management"
        ],
        "summary": "Set the merchant primary settlement account",
        "description": "Changes the merchant settlement account to an account already linked to the merchant.",
        "parameters": [
          {
            "name": "accountId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "example": "MBANK_1A2B"
          },
          {
            "name": "merchantId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "example": "MERCH_TAMIMI_KSA"
          }
        ],
        "responses": {
          "200": {
            "description": "Primary settlement account updated"
          },
          "404": {
            "description": "Merchant account not found"
          }
        }
      }
    },
    "/api/v1/merchant/payment-links": {
      "post": {
        "tags": [
          "Merchant: Remote Payment Links"
        ],
        "summary": "Create Remote Payment Link",
        "parameters": [
          {
            "name": "merchantId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "example": "MERCH_TAMIMI_KSA"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "titleEn",
                  "amount"
                ],
                "properties": {
                  "titleEn": {
                    "type": "string",
                    "example": "Corporate Coffee Order"
                  },
                  "titleAr": {
                    "type": "string",
                    "example": "طلب قهوة للشركات"
                  },
                  "amount": {
                    "type": "number",
                    "example": 450
                  },
                  "customerMobile": {
                    "type": "string",
                    "example": "0501234567"
                  },
                  "customerName": {
                    "type": "string",
                    "example": "Tariq Al-Harbi"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Payment link created with checkout URL"
          }
        }
      },
      "get": {
        "tags": [
          "Merchant: Remote Payment Links"
        ],
        "summary": "List Merchant Payment Links",
        "parameters": [
          {
            "name": "merchantId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "example": "MERCH_TAMIMI_KSA"
          }
        ],
        "responses": {
          "200": {
            "description": "Payment links list"
          }
        }
      }
    },
    "/api/v1/pay/link/{linkId}": {
      "get": {
        "tags": [
          "Merchant: Remote Payment Links"
        ],
        "summary": "Public Checkout View for Payment Link",
        "parameters": [
          {
            "name": "linkId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "example": "PLINK_1A2B3C"
          }
        ],
        "responses": {
          "200": {
            "description": "Payment link details with QR and invoice data"
          }
        }
      }
    },
    "/api/v1/pay/link/{linkId}/pay": {
      "post": {
        "tags": [
          "Merchant: Remote Payment Links"
        ],
        "summary": "Pay Payment Link via Customer Mobile & PIN",
        "parameters": [
          {
            "name": "linkId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "example": "PLINK_1A2B3C"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "customerMobile",
                  "pin"
                ],
                "properties": {
                  "customerMobile": {
                    "type": "string",
                    "example": "0501234567"
                  },
                  "pin": {
                    "type": "string",
                    "example": "123456"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Link paid successfully"
          }
        }
      }
    },
    "/api/v1/merchant/reports/sales": {
      "get": {
        "tags": [
          "Merchant: Business Reports"
        ],
        "summary": "Get Sales Report with VAT Breakdown",
        "parameters": [
          {
            "name": "merchantId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "example": "MERCH_TAMIMI_KSA"
          },
          {
            "name": "period",
            "in": "query",
            "schema": {
              "type": "string",
              "default": "month"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Sales report metrics"
          }
        }
      }
    },
    "/api/v1/merchant/reports/settlement": {
      "get": {
        "tags": [
          "Merchant: Business Reports"
        ],
        "summary": "Get Bank Settlements & Payout Report",
        "parameters": [
          {
            "name": "merchantId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "example": "MERCH_TAMIMI_KSA"
          }
        ],
        "responses": {
          "200": {
            "description": "Settlement report records"
          }
        }
      }
    },
    "/api/v1/merchant/reports/reconciliation": {
      "get": {
        "tags": [
          "Merchant: Business Reports"
        ],
        "summary": "Get SAMA Interbank Daily Reconciliation Report",
        "parameters": [
          {
            "name": "merchantId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "example": "MERCH_TAMIMI_KSA"
          },
          {
            "name": "date",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "example": "2026-10-08"
          }
        ],
        "responses": {
          "200": {
            "description": "Reconciliation report"
          }
        }
      }
    },
    "/api/v1/merchant/reports/export": {
      "post": {
        "tags": [
          "Merchant: Business Reports"
        ],
        "summary": "Export Reports in CSV or JSON Format",
        "parameters": [
          {
            "name": "merchantId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "example": "MERCH_TAMIMI_KSA"
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "reportType": {
                    "type": "string",
                    "enum": [
                      "SALES",
                      "SETTLEMENT"
                    ],
                    "default": "SALES"
                  },
                  "format": {
                    "type": "string",
                    "enum": [
                      "CSV",
                      "JSON"
                    ],
                    "default": "CSV"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Exported file payload"
          }
        }
      }
    },
    "/api/v1/merchant/profile": {
      "get": {
        "tags": [
          "Merchant: Store Management"
        ],
        "summary": "Get Merchant Legal & Profile Details",
        "parameters": [
          {
            "name": "merchantId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "example": "MERCH_TAMIMI_KSA"
          }
        ],
        "responses": {
          "200": {
            "description": "Profile details"
          }
        }
      },
      "put": {
        "tags": [
          "Merchant: Store Management"
        ],
        "summary": "Update Profile & Trade Information",
        "parameters": [
          {
            "name": "merchantId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "example": "MERCH_TAMIMI_KSA"
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "email": {
                    "type": "string",
                    "example": "finance@tamimi.sa"
                  },
                  "city": {
                    "type": "string",
                    "example": "Riyadh"
                  },
                  "address": {
                    "type": "string",
                    "example": "Olaya Commercial Street"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Profile updated"
          }
        }
      }
    },
    "/api/v1/merchant/stores": {
      "get": {
        "tags": [
          "Merchant: Store Management"
        ],
        "summary": "List Merchant Store Branches",
        "parameters": [
          {
            "name": "merchantId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "example": "MERCH_TAMIMI_KSA"
          }
        ],
        "responses": {
          "200": {
            "description": "List of stores"
          }
        }
      },
      "post": {
        "tags": [
          "Merchant: Store Management"
        ],
        "summary": "Add Store Branch with mada POS Terminal",
        "parameters": [
          {
            "name": "merchantId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "example": "MERCH_TAMIMI_KSA"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "branchNameEn",
                  "city"
                ],
                "properties": {
                  "branchNameEn": {
                    "type": "string",
                    "example": "Tamimi Olaya Express"
                  },
                  "branchNameAr": {
                    "type": "string",
                    "example": "أسواق التميمي العليا إكسبريس"
                  },
                  "city": {
                    "type": "string",
                    "example": "Riyadh"
                  },
                  "address": {
                    "type": "string",
                    "example": "Olaya Commercial St"
                  },
                  "contactMobile": {
                    "type": "string",
                    "example": "0599112233"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Store branch added"
          }
        }
      }
    },
    "/api/v1/merchant/stores/{storeId}": {
      "delete": {
        "tags": [
          "Merchant: Store Management"
        ],
        "summary": "Deactivate Store Branch",
        "parameters": [
          {
            "name": "storeId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "example": "STORE_1A2B"
          },
          {
            "name": "merchantId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "example": "MERCH_TAMIMI_KSA"
          }
        ],
        "responses": {
          "200": {
            "description": "Store deactivated"
          }
        }
      }
    },
    "/api/v1/merchant/support/tickets": {
      "post": {
        "tags": [
          "Merchant: Help & Support"
        ],
        "summary": "Create Operations Support Ticket",
        "parameters": [
          {
            "name": "merchantId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "example": "MERCH_TAMIMI_KSA"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "subject",
                  "message"
                ],
                "properties": {
                  "subject": {
                    "type": "string",
                    "example": "Settlement schedule inquiry"
                  },
                  "category": {
                    "type": "string",
                    "enum": [
                      "SETTLEMENT",
                      "REFUND",
                      "TERMINAL",
                      "GENERAL"
                    ],
                    "default": "SETTLEMENT"
                  },
                  "priority": {
                    "type": "string",
                    "enum": [
                      "LOW",
                      "MEDIUM",
                      "HIGH"
                    ],
                    "default": "MEDIUM"
                  },
                  "message": {
                    "type": "string",
                    "example": "Can we configure multiple daily settlement sweeps?"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Support ticket created"
          }
        }
      },
      "get": {
        "tags": [
          "Merchant: Help & Support"
        ],
        "summary": "List Support Tickets",
        "parameters": [
          {
            "name": "merchantId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "example": "MERCH_TAMIMI_KSA"
          }
        ],
        "responses": {
          "200": {
            "description": "Tickets list"
          }
        }
      }
    },
    "/api/v1/merchant/support/chatbot": {
      "post": {
        "tags": [
          "Merchant: Help & Support"
        ],
        "summary": "Query SAMA Payment Intelligent AI Chatbot",
        "description": "Instant bilingual responses for settlements, pacs.004 refunds, ZATCA e-invoicing, QR acceptance, and SAMA limits.",
        "parameters": [
          {
            "name": "merchantId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "example": "MERCH_TAMIMI_KSA"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "query"
                ],
                "properties": {
                  "query": {
                    "type": "string",
                    "example": "How does SettleNow work?"
                  },
                  "language": {
                    "type": "string",
                    "enum": [
                      "en",
                      "ar"
                    ],
                    "default": "en"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Bilingual intelligent response"
          }
        }
      }
    },
    "/api/v1/merchant/settings": {
      "get": {
        "tags": [
          "Merchant: Settings & Security"
        ],
        "summary": "Get Merchant Settings & Notification Preferences",
        "parameters": [
          {
            "name": "merchantId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "example": "MERCH_TAMIMI_KSA"
          }
        ],
        "responses": {
          "200": {
            "description": "Settings overview"
          }
        }
      },
      "put": {
        "tags": [
          "Merchant: Settings & Security"
        ],
        "summary": "Update Settlement Mode & Notification Webhooks",
        "parameters": [
          {
            "name": "merchantId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "example": "MERCH_TAMIMI_KSA"
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "autoSettle": {
                    "type": "boolean",
                    "example": true
                  },
                  "webhookUrl": {
                    "type": "string",
                    "example": "https://api.tamimi.sa/webhooks/sama"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Settings saved"
          }
        }
      }
    },
    "/api/v1/merchant/settings/api-keys/regenerate": {
      "post": {
        "tags": [
          "Merchant: Settings & Security"
        ],
        "summary": "Regenerate Live API Credentials",
        "parameters": [
          {
            "name": "merchantId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "example": "MERCH_TAMIMI_KSA"
          }
        ],
        "responses": {
          "200": {
            "description": "New live API key and secret generated"
          }
        }
      }
    },
    "/api/v1/merchant/team": {
      "get": {
        "tags": [
          "Merchant: Team & Permissions"
        ],
        "summary": "List Staff Team Members & Roles",
        "parameters": [
          {
            "name": "merchantId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "example": "MERCH_TAMIMI_KSA"
          }
        ],
        "responses": {
          "200": {
            "description": "Team members list"
          }
        }
      },
      "post": {
        "tags": [
          "Merchant: Team & Permissions"
        ],
        "summary": "Add Staff Member with Operational Permissions",
        "parameters": [
          {
            "name": "merchantId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "example": "MERCH_TAMIMI_KSA"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "nameEn",
                  "mobileNumber",
                  "role"
                ],
                "properties": {
                  "nameEn": {
                    "type": "string",
                    "example": "Omar Al-Ghamdi"
                  },
                  "nameAr": {
                    "type": "string",
                    "example": "عمر الغامدي"
                  },
                  "mobileNumber": {
                    "type": "string",
                    "example": "0591234567"
                  },
                  "role": {
                    "type": "string",
                    "enum": [
                      "ADMIN",
                      "MANAGER",
                      "ACCOUNTANT",
                      "CASHIER"
                    ],
                    "default": "CASHIER"
                  },
                  "permissions": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "example": [
                      "CAN_VIEW_REPORTS",
                      "CAN_CREATE_PAYMENT_LINKS"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Team member added"
          }
        }
      }
    },
    "/api/v1/merchant/team/{memberId}": {
      "delete": {
        "tags": [
          "Merchant: Team & Permissions"
        ],
        "summary": "Remove Staff Team Member",
        "parameters": [
          {
            "name": "memberId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "example": "MEM_1A2B"
          },
          {
            "name": "merchantId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "example": "MERCH_TAMIMI_KSA"
          }
        ],
        "responses": {
          "200": {
            "description": "Staff member removed"
          }
        }
      }
    },
    "/api/v1/merchants/demo-list": {
      "get": {
        "tags": [
          "Demo Environment & Testing"
        ],
        "summary": "List 10 Pre-Configured Saudi Merchants for Testing",
        "description": "Returns all 10 realistic Saudi merchants across 10 commercial banks with testing credentials (PIN: 123456, Password: 123456).",
        "responses": {
          "200": {
            "description": "10 merchants catalog"
          }
        }
      }
    },
    "/api/v1/merchants/seed-10": {
      "post": {
        "tags": [
          "Demo Environment & Testing"
        ],
        "summary": "Re-Seed 10 Demo Merchants into Database",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "force": {
                    "type": "boolean",
                    "default": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "10 demo merchants seeded"
          }
        }
      }
    },
    "/api/v1/database/purge-and-seed-10-users": {
      "post": {
        "tags": [
          "Demo Environment & Testing"
        ],
        "summary": "Purge & Re-Seed 10 Consumer Demo Users (3 Accounts Each)",
        "responses": {
          "200": {
            "description": "10 users with 30 accounts seeded"
          }
        }
      }
    },
    "/api/v1/database/info": {
      "get": {
        "tags": [
          "Demo Environment & Testing"
        ],
        "summary": "Get Database Info & PostgreSQL Connection Details",
        "responses": {
          "200": {
            "description": "Database provider and live table row counts"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "HealthResponse": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "example": "UP"
          },
          "statusDescEn": {
            "type": "string",
            "example": "SAMA sarie & mada Switch operational and healthy"
          },
          "statusDescAr": {
            "type": "string",
            "example": "مقسم سريع ومدى التابع للبنك المركزي السعودي يعمل بكفاءة وجاهزية تامة"
          },
          "switchNameEn": {
            "type": "string",
            "example": "Saudi Central Bank (SAMA) sarie & mada Switch"
          },
          "currency": {
            "type": "string",
            "example": "SAR"
          },
          "stats": {
            "type": "object",
            "properties": {
              "usersCount": {
                "type": "integer"
              },
              "merchantsCount": {
                "type": "integer"
              },
              "transactionsCount": {
                "type": "integer"
              },
              "bankAccountsCount": {
                "type": "integer"
              }
            }
          }
        }
      },
      "BanksResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "example": true
          },
          "currency": {
            "type": "string",
            "example": "SAR"
          },
          "banks": {
            "type": "object",
            "additionalProperties": {
              "type": "object",
              "properties": {
                "bic": {
                  "type": "string",
                  "example": "NCBKSARI"
                },
                "code": {
                  "type": "string",
                  "example": "10"
                },
                "nameEn": {
                  "type": "string",
                  "example": "Saudi National Bank (SNB)"
                },
                "nameAr": {
                  "type": "string",
                  "example": "البنك الأهلي السعودي"
                },
                "routingCode": {
                  "type": "string",
                  "example": "NCBKSA"
                }
              }
            }
          }
        }
      },
      "UserRegisterRequest": {
        "type": "object",
        "required": [
          "mobileNumber",
          "nationalId"
        ],
        "properties": {
          "mobileNumber": {
            "type": "string",
            "example": "0501234567"
          },
          "nationalId": {
            "type": "string",
            "example": "1098765432"
          },
          "fullNameEn": {
            "type": "string",
            "example": "Tariq Al-Harbi"
          },
          "fullNameAr": {
            "type": "string",
            "example": "طارق ناصر الحربي"
          },
          "deviceFingerprint": {
            "type": "string",
            "example": "DEV_5960cb0df1b2e489"
          }
        }
      },
      "P2PPaymentRequest": {
        "type": "object",
        "required": [
          "amount",
          "pin"
        ],
        "properties": {
          "remitterMobile": {
            "type": "string",
            "example": "0501234567"
          },
          "remitterIban": {
            "type": "string",
            "example": "SA0310000001099887766554"
          },
          "beneficiaryMobile": {
            "type": "string",
            "example": "0502345678"
          },
          "beneficiaryIban": {
            "type": "string",
            "example": "SA0380000001099887766555"
          },
          "amount": {
            "type": "number",
            "example": 100
          },
          "pin": {
            "type": "string",
            "example": "123456"
          },
          "note": {
            "type": "string",
            "example": "Weekend trip share"
          }
        }
      },
      "TransactionResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "example": true
          },
          "rrn": {
            "type": "string",
            "example": "628114062639"
          },
          "utr": {
            "type": "string",
            "example": "SARIE20261008628114062639"
          },
          "amount": {
            "type": "number",
            "example": 100
          },
          "currency": {
            "type": "string",
            "example": "SAR"
          },
          "status": {
            "type": "string",
            "example": "SUCCESS"
          },
          "remitter": {
            "type": "object"
          },
          "beneficiary": {
            "type": "object"
          },
          "executionTimeMs": {
            "type": "number",
            "example": 1.15
          }
        }
      },
      "MerchantRegisterRequest": {
        "type": "object",
        "required": [
          "tradeNameEn",
          "mobileNumber"
        ],
        "properties": {
          "tradeNameEn": {
            "type": "string",
            "example": "Tamimi Markets"
          },
          "tradeNameAr": {
            "type": "string",
            "example": "أسواق التميمي"
          },
          "businessNameEn": {
            "type": "string",
            "example": "Tamimi Markets Company"
          },
          "businessNameAr": {
            "type": "string",
            "example": "شركة أسواق التميمي"
          },
          "mobileNumber": {
            "type": "string",
            "example": "0599112233"
          },
          "email": {
            "type": "string",
            "example": "finance@tamimi.sa"
          },
          "mcc": {
            "type": "string",
            "example": "5411"
          },
          "crNumber": {
            "type": "string",
            "example": "1010223344"
          },
          "vatNumber": {
            "type": "string",
            "example": "300055443300003"
          },
          "settlementBankCode": {
            "type": "string",
            "example": "NCBK"
          },
          "settlementIban": {
            "type": "string",
            "example": "SA0310000009999000011101"
          },
          "city": {
            "type": "string",
            "example": "Al Khobar"
          },
          "address": {
            "type": "string",
            "example": "King Fahd Road"
          }
        }
      }
    }
  }
}