{
  "openapi": "3.1.0",
  "info": {
    "title": "Vintage Vibes ERP & Makkani AI Enterprise Retail OS API",
    "version": "2026.4.0",
    "summary": "Public OpenAPI specification for the Makkani AI Omnichannel Retail, Bale WMS, AI Garment Studio & Double-Entry Accounting ERP.",
    "description": "Production REST API contract powering Vintage Vibes General Trading LLC SPC (UAE) and global multi-country licensed deployments (UAE FTA, Pakistan FBR, KSA ZATCA, UK, US, EU). Authenticated modules require Bearer JWT tokens enforced by RBAC permissions and immutable audit logging.",
    "contact": {
      "name": "Makkani AI Enterprise Licensing & Support",
      "url": "https://vintagevibesgk.com/enterprise.html",
      "email": "mmakkani@gmail.com"
    },
    "license": {
      "name": "Makkani AI Proprietary Commercial License (All Rights Reserved Worldwide)",
      "url": "https://vintagevibesgk.com/license.html"
    }
  },
  "servers": [
    {
      "url": "https://vintagevibesgk.com",
      "description": "Primary UAE Production Node"
    }
  ],
  "tags": [
    { "name": "Health", "description": "System health & telemetry readiness probes" },
    { "name": "Storefront & Catalog", "description": "Public 1-of-1 SKU discovery, cart reservation, and checkout endpoints" },
    { "name": "Bale WMS & Purchase", "description": "Container/bale sorting, landed COGS calculation, and purchase invoices (RBAC protected)" },
    { "name": "Sales & POS", "description": "Omnichannel POS billing, live auction invoicing, and gate passes (RBAC protected)" },
    { "name": "Finance & Multi-Tax Ledger", "description": "Double-entry Chart of Accounts, vouchers, UAE FTA / Pakistan FBR / KSA ZATCA tax ledgers" },
    { "name": "Registry & Parties", "description": "Suppliers, wholesale buyers, retail customers, and COA auto-linking" },
    { "name": "HR & Payroll", "description": "Staff attendance, shifts, and payroll sheets" },
    { "name": "Global Setup & Audit", "description": "Multi-country currency, fiscal tax profiles, and immutable audit trail" }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "description": "Operator JWT issued after RBAC authentication. Enforces module-level read/write permissions."
      }
    },
    "schemas": {
      "HealthResponse": {
        "type": "object",
        "properties": {
          "status": { "type": "string", "example": "ok" },
          "timestamp": { "type": "string", "format": "date-time" },
          "database": { "type": "string", "example": "connected" }
        }
      },
      "ProductItem": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "sku": { "type": "string", "example": "VV-CAR-2026-0142" },
          "title": { "type": "string" },
          "brand": { "type": "string" },
          "category": { "type": "string" },
          "grade": { "type": "string", "enum": ["Grail", "Grade A", "Grade B", "Scrap"] },
          "price": { "type": "number" },
          "currency": { "type": "string", "example": "AED" },
          "status": { "type": "string", "enum": ["in_stock", "reserved", "sold"] },
          "measurements": { "type": "object", "additionalProperties": true }
        }
      },
      "BaleSession": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "supplierId": { "type": "string" },
          "baleCode": { "type": "string" },
          "grossWeightKg": { "type": "number" },
          "tareWeightKg": { "type": "number" },
          "landedCostTotal": { "type": "number" },
          "currency": { "type": "string", "example": "USD" },
          "sortedPiecesCount": { "type": "integer" }
        }
      },
      "TaxProfile": {
        "type": "object",
        "properties": {
          "countryCode": { "type": "string", "example": "PK" },
          "taxAuthority": { "type": "string", "example": "FBR" },
          "currency": { "type": "string", "example": "PKR" },
          "standardTaxRate": { "type": "number", "example": 18.0 },
          "invoicePrefix": { "type": "string", "example": "INV-PK-" }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "error": { "type": "string" },
          "code": { "type": "string" }
        }
      }
    }
  },
  "paths": {
    "/api/health": {
      "get": {
        "tags": ["Health"],
        "summary": "Check ERP backend and PostgreSQL health",
        "responses": {
          "200": {
            "description": "Service is operational",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/HealthResponse" }
              }
            }
          }
        }
      }
    },
    "/api/ecommerce/catalog": {
      "get": {
        "tags": ["Storefront & Catalog"],
        "summary": "List available 1-of-1 curated inventory items",
        "parameters": [
          { "name": "category", "in": "query", "schema": { "type": "string" } },
          { "name": "brand", "in": "query", "schema": { "type": "string" } },
          { "name": "currency", "in": "query", "schema": { "type": "string", "example": "AED" } }
        ],
        "responses": {
          "200": {
            "description": "Array of live storefront SKUs",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": { "$ref": "#/components/schemas/ProductItem" }
                }
              }
            }
          }
        }
      }
    },
    "/api/ecommerce/orders": {
      "post": {
        "tags": ["Storefront & Catalog"],
        "summary": "Submit an authenticated or guest storefront order with cart reservation lock",
        "responses": {
          "201": { "description": "Order created and inventory locked atomically" },
          "409": { "description": "SKU already reserved or sold" }
        }
      }
    },
    "/api/purchase/bale-sessions": {
      "get": {
        "tags": ["Bale WMS & Purchase"],
        "summary": "List container and bale sorting sessions with landed COGS",
        "security": [{ "bearerAuth": [] }],
        "responses": {
          "200": {
            "description": "Bale sorting sessions",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": { "$ref": "#/components/schemas/BaleSession" }
                }
              }
            }
          },
          "401": { "description": "Unauthorized" }
        }
      }
    },
    "/api/purchase/invoices": {
      "get": {
        "tags": ["Bale WMS & Purchase"],
        "summary": "List supplier purchase invoices and inward gate passes",
        "security": [{ "bearerAuth": [] }],
        "responses": {
          "200": { "description": "Purchase invoices list" },
          "401": { "description": "Unauthorized" }
        }
      }
    },
    "/api/sales/invoices": {
      "get": {
        "tags": ["Sales & POS"],
        "summary": "List wholesale, POS, and live-stream sales invoices",
        "security": [{ "bearerAuth": [] }],
        "responses": {
          "200": { "description": "Sales invoices" },
          "401": { "description": "Unauthorized" }
        }
      },
      "post": {
        "tags": ["Sales & POS"],
        "summary": "Create a tax-compliant POS or wholesale invoice and post double-entry journal lines",
        "security": [{ "bearerAuth": [] }],
        "responses": {
          "201": { "description": "Invoice issued and general ledger updated" },
          "401": { "description": "Unauthorized" }
        }
      }
    },
    "/api/finance/vouchers": {
      "get": {
        "tags": ["Finance & Multi-Tax Ledger"],
        "summary": "Query double-entry payment, receipt, and journal vouchers",
        "security": [{ "bearerAuth": [] }],
        "responses": {
          "200": { "description": "Financial vouchers and balanced journal lines" },
          "401": { "description": "Unauthorized" }
        }
      }
    },
    "/api/finance/coa": {
      "get": {
        "tags": ["Finance & Multi-Tax Ledger"],
        "summary": "Retrieve hierarchical Chart of Accounts balances",
        "security": [{ "bearerAuth": [] }],
        "responses": {
          "200": { "description": "Chart of Accounts tree" },
          "401": { "description": "Unauthorized" }
        }
      }
    },
    "/api/parties": {
      "get": {
        "tags": ["Registry & Parties"],
        "summary": "List registered suppliers, wholesale clients, and retail accounts",
        "security": [{ "bearerAuth": [] }],
        "responses": {
          "200": { "description": "Parties registry" },
          "401": { "description": "Unauthorized" }
        }
      }
    },
    "/api/hr/employees": {
      "get": {
        "tags": ["HR & Payroll"],
        "summary": "List active employees, attendance summaries, and payroll metadata",
        "security": [{ "bearerAuth": [] }],
        "responses": {
          "200": { "description": "Employee directory" },
          "401": { "description": "Unauthorized" }
        }
      }
    },
    "/api/setup/tax-profiles": {
      "get": {
        "tags": ["Global Setup & Audit"],
        "summary": "Retrieve configured multi-country tax & currency profiles (UAE FTA, Pakistan FBR, KSA ZATCA, UK, US, EU)",
        "security": [{ "bearerAuth": [] }],
        "responses": {
          "200": {
            "description": "Active country localization & tax settings",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": { "$ref": "#/components/schemas/TaxProfile" }
                }
              }
            }
          },
          "401": { "description": "Unauthorized" }
        }
      }
    },
    "/api/audit/logs": {
      "get": {
        "tags": ["Global Setup & Audit"],
        "summary": "Read immutable operator audit trail events",
        "security": [{ "bearerAuth": [] }],
        "responses": {
          "200": { "description": "Immutable audit log entries" },
          "401": { "description": "Unauthorized" }
        }
      }
    }
  }
}
