{
  "openapi": "3.0.3",
  "info": {
    "title": "AVS Central Services Platform API",
    "description": "Central unified integration layer for Arivahly Ventures applications and authorised merchants.",
    "version": "1.2.0",
    "contact": {
      "name": "AVS Developer Support",
      "url": "https://admin.arivahly.in",
      "email": "dev@arivahly.in"
    }
  },
  "servers": [
    {
      "url": "https://api.arivahly.in/v1",
      "description": "Production Environment"
    },
    {
      "url": "https://api.arivahly.in/api/v1",
      "description": "Backwards-Compatible Prefix"
    },
    {
      "url": "http://localhost:3000/v1",
      "description": "Local Development"
    }
  ],
  "security": [
    {
      "AppCredentials": []
    }
  ],
  "components": {
    "securitySchemes": {
      "AppCredentials": {
        "type": "apiKey",
        "name": "X-AVS-Api-Key",
        "in": "header",
        "description": "Combined with X-AVS-App-Id header for application authentication."
      },
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT"
      }
    }
  },
  "paths": {
    "/health": {
      "get": {
        "summary": "Platform Health Check",
        "description": "Returns real-time operational status of central database, vaults, and background workers.",
        "responses": {
          "200": {
            "description": "All systems operational"
          }
        }
      }
    },
    "/auth/token": {
      "post": {
        "summary": "Generate Ephemeral Token",
        "description": "Exchanges App ID and API Key for a scoped short-lived Bearer token.",
        "responses": {
          "200": {
            "description": "Token generated"
          },
          "401": {
            "description": "Invalid credentials"
          }
        }
      }
    },
    "/applications/me": {
      "get": {
        "summary": "Current Application Profile",
        "description": "Returns metadata, assigned permissions, and active environment for the caller.",
        "responses": {
          "200": {
            "description": "Application metadata"
          }
        }
      }
    },
    "/whatsapp/send-template": {
      "post": {
        "summary": "Send WhatsApp Template",
        "description": "Dispatches Meta-approved business templates via central or merchant WhatsApp channel.",
        "responses": {
          "200": {
            "description": "Message queued/sent"
          }
        }
      }
    },
    "/whatsapp/send-invoice": {
      "post": {
        "summary": "Send WhatsApp Invoice Link",
        "description": "Dispatches digital invoice link via WhatsApp to the designated recipient.",
        "responses": {
          "200": {
            "description": "Invoice sent"
          }
        }
      }
    },
    "/email/send": {
      "post": {
        "summary": "Send Transactional Email",
        "description": "Delivers email via central AVS SMTP or merchant-owned verified sender domain.",
        "responses": {
          "200": {
            "description": "Email dispatched"
          }
        }
      }
    },
    "/documents/upload": {
      "post": {
        "summary": "Upload Digital Invoice / Document",
        "description": "Uploads and digests a PDF/document for hosting on invoices.arivahly.in.",
        "responses": {
          "201": {
            "description": "Document created and token issued"
          }
        }
      }
    },
    "/customers/register": {
      "post": {
        "summary": "Register Central Customer",
        "description": "Registers or updates a customer profile with phone normalization.",
        "responses": {
          "200": {
            "description": "Customer resolved"
          }
        }
      }
    },
    "/cards/identify": {
      "post": {
        "summary": "Identify AVS Card",
        "description": "Resolves physical/NFC card identifier to customer and merchant-specific prepaid balance.",
        "responses": {
          "200": {
            "description": "Card identified"
          }
        }
      }
    },
    "/integrations/merchant": {
      "post": {
        "summary": "Configure Merchant Integration",
        "description": "Saves isolated credentials for Zomato, Swiggy, BYO WhatsApp, or BYO SMTP.",
        "responses": {
          "200": {
            "description": "Integration configured"
          }
        }
      },
      "get": {
        "summary": "List Merchant Integrations",
        "description": "Returns active external integrations for the caller's merchant context.",
        "responses": {
          "200": {
            "description": "Integrations list"
          }
        }
      }
    }
  }
}