{
  "openapi": "3.0.3",
  "info": {
    "title": "Nexora Reseller & Developer API v1",
    "version": "1.0.0",
    "description": "High-performance, crypto-powered digital accounts and keys marketplace API for automated resellers, bots, and high-frequency bulk ordering systems."
  },
  "servers": [
    {
      "url": "https://api.nexora.com",
      "description": "Production Server"
    },
    {
      "url": "http://localhost:3000",
      "description": "Local Development Server"
    }
  ],
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key",
        "description": "24-byte hexadecimal API key secret generated from your Reseller Dashboard (e.g. nx_live_...)"
      }
    },
    "schemas": {
      "Product": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "example": "clx123abc456" },
          "name": { "type": "string", "example": "Facebook Accounts - USA Aged 2FA" },
          "slug": { "type": "string", "example": "facebook-accounts-usa-aged" },
          "price": { "type": "number", "example": 1.25 },
          "currency": { "type": "string", "example": "USD" },
          "category": { "type": "string", "example": "Facebook Accounts" },
          "categorySlug": { "type": "string", "example": "facebook-accounts" },
          "inStock": { "type": "boolean", "example": true },
          "availableStock": { "type": "integer", "example": 450 }
        }
      },
      "WalletBalance": {
        "type": "object",
        "properties": {
          "success": { "type": "boolean", "example": true },
          "userId": { "type": "string", "example": "usr_789xyz" },
          "email": { "type": "string", "example": "reseller@domain.com" },
          "balance": { "type": "number", "example": 450.75 },
          "lockedBalance": { "type": "number", "example": 0.00 },
          "currency": { "type": "string", "example": "USD" },
          "updatedAt": { "type": "string", "format": "date-time" }
        }
      },
      "CreateOrderItem": {
        "type": "object",
        "required": ["productId", "quantity"],
        "properties": {
          "productId": { "type": "string", "example": "clx123abc456" },
          "quantity": { "type": "integer", "minimum": 1, "example": 5 }
        }
      },
      "CreateOrderRequest": {
        "type": "object",
        "properties": {
          "productId": { "type": "string", "description": "Single-item purchase shortcut" },
          "quantity": { "type": "integer", "minimum": 1, "description": "Single-item quantity shortcut" },
          "items": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/CreateOrderItem" }
          }
        }
      },
      "DeliveredOrder": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "example": "ord_998877" },
          "orderNumber": { "type": "string", "example": "ORD-API-1731600000-A1B2" },
          "status": { "type": "string", "example": "COMPLETED" },
          "paymentStatus": { "type": "string", "example": "PAID" },
          "totalAmount": { "type": "number", "example": 6.25 },
          "currency": { "type": "string", "example": "USD" },
          "createdAt": { "type": "string", "format": "date-time" },
          "items": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "productId": { "type": "string" },
                "productName": { "type": "string" },
                "quantity": { "type": "integer" },
                "unitPrice": { "type": "number" },
                "totalPrice": { "type": "number" },
                "credentials": {
                  "type": "array",
                  "items": { "type": "string" },
                  "example": ["user@mail.com:password:2FA_SECRET"]
                }
              }
            }
          }
        }
      },
      "ApiError": {
        "type": "object",
        "properties": {
          "success": { "type": "boolean", "example": false },
          "error": { "type": "string", "example": "Error description message." }
        }
      }
    }
  },
  "security": [
    {
      "ApiKeyAuth": []
    }
  ],
  "paths": {
    "/api/v1/products": {
      "get": {
        "summary": "Fetch Active Product Catalog & Live Stock",
        "description": "Returns all active marketplace products with live inventory counts. Rate limit: 60 req/min.",
        "parameters": [
          { "name": "category", "in": "query", "schema": { "type": "string" }, "description": "Filter by category slug" },
          { "name": "search", "in": "query", "schema": { "type": "string" }, "description": "Keyword search across product names" },
          { "name": "limit", "in": "query", "schema": { "type": "integer", "default": 50, "maximum": 100 } },
          { "name": "offset", "in": "query", "schema": { "type": "integer", "default": 0 } }
        ],
        "responses": {
          "200": {
            "description": "Catalog retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean" },
                    "total": { "type": "integer" },
                    "limit": { "type": "integer" },
                    "offset": { "type": "integer" },
                    "products": { "type": "array", "items": { "$ref": "#/components/schemas/Product" } }
                  }
                }
              }
            }
          },
          "401": { "description": "Invalid or missing API key" },
          "429": { "description": "Rate limit exceeded" }
        }
      }
    },
    "/api/v1/balance": {
      "get": {
        "summary": "Get Reseller Wallet Balance",
        "description": "Returns current available USD balance and wallet status. Rate limit: 60 req/min.",
        "responses": {
          "200": {
            "description": "Wallet balance retrieved",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/WalletBalance" }
              }
            }
          },
          "401": { "description": "Unauthorized" },
          "429": { "description": "Rate limit exceeded" }
        }
      }
    },
    "/api/v1/orders": {
      "post": {
        "summary": "Programmatic Bulk or Single Purchase",
        "description": "Atomically purchases items using verified wallet balance. Immediate vault credentials delivered. Requires Idempotency-Key header. Rate limit: 15 req/min.",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": { "type": "string" },
            "description": "Unique client-generated UUID to guarantee exactly-once purchase execution"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/CreateOrderRequest" }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Order successfully created, paid, and credentials fulfilled",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean" },
                    "order": { "$ref": "#/components/schemas/DeliveredOrder" }
                  }
                }
              }
            }
          },
          "400": { "description": "Invalid input format or quantity" },
          "402": { "description": "Insufficient wallet funds" },
          "409": { "description": "Out of stock or concurrent reservation conflict" },
          "429": { "description": "Write rate limit exceeded (15/min)" }
        }
      }
    },
    "/api/v1/orders/{id}": {
      "get": {
        "summary": "Retrieve Order & Purchased Credentials",
        "description": "Fetches fulfillment status and delivered account details for an order owned by the caller. Rate limit: 60 req/min.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": { "type": "string" },
            "description": "Order UUID or order number (e.g. ORD-API-...)"
          }
        ],
        "responses": {
          "200": {
            "description": "Order retrieved",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean" },
                    "order": { "$ref": "#/components/schemas/DeliveredOrder" }
                  }
                }
              }
            }
          },
          "401": { "description": "Unauthorized" },
          "404": { "description": "Order not found or belongs to another user" },
          "429": { "description": "Rate limit exceeded" }
        }
      }
    }
  }
}
