{
  "openapi": "3.1.0",
  "info": {
    "title": "Meta Reva Autonomous Agent & ERP WhatsApp API",
    "version": "1.2.0",
    "description": "Public API specification for AI agents to query live ERP inventory, process B2B orders, and retrieve customer statements via Meta Reva.",
    "contact": {
      "name": "Meta Reva Agent Support",
      "url": "https://metareva.com/iletisim",
      "email": "destek@metareva.com"
    }
  },
  "servers": [
    {
      "url": "https://metareva.com/api/v1",
      "description": "Production API Server"
    }
  ],
  "paths": {
    "/agent/erp-query": {
      "post": {
        "summary": "Query live ERP inventory and product price",
        "description": "Allows autonomous buyer agents to check live stock quantity, unit prices, and warehouse locations across connected ERPs (Logo, Mikro, Netsis).",
        "operationId": "checkStockInventory",
        "x-payment-info": {
          "protocol": "mpp/1.0",
          "pricing_model": "per_request",
          "price": {
            "currency": "USD",
            "amount": "0.01",
            "micropayment_tokens": ["USDC", "SAT"]
          },
          "settlement": {
            "methods": ["x402", "ap2_mandate", "prepaid_api_key"],
            "details_url": "https://metareva.com/.well-known/x402.json"
          }
        },
        "security": [
          { "BearerAuth": [] },
          { "x402Auth": [] }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "sku": { "type": "string", "example": "STK-LOGO-1002" },
                  "warehouse_id": { "type": "string", "example": "WH-01" }
                },
                "required": ["sku"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Inventory query successful",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": { "type": "boolean", "example": true },
                    "sku": { "type": "string", "example": "STK-LOGO-1002" },
                    "available_qty": { "type": "number", "example": 450 },
                    "unit_price": { "type": "number", "example": 85.50 },
                    "currency": { "type": "string", "example": "TRY" },
                    "warehouse": { "type": "string", "example": "Ana Depo" }
                  }
                }
              }
            }
          },
          "402": {
            "description": "Payment Required (x402 paywall)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": { "type": "string", "example": "Payment Required" },
                    "accepts": { "type": "array" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/agent/order-submit": {
      "post": {
        "summary": "Submit B2B Purchase Order to ERP",
        "description": "Directly creates a commercial purchase order ticket inside connected ERP with credit line verification and lot reservations.",
        "operationId": "submitB2BOrder",
        "x-payment-info": {
          "protocol": "mpp/1.0",
          "pricing_model": "per_request",
          "price": {
            "currency": "USD",
            "amount": "0.10",
            "micropayment_tokens": ["USDC", "SAT"]
          },
          "settlement": {
            "methods": ["x402", "ap2_mandate", "prepaid_api_key"],
            "details_url": "https://metareva.com/.well-known/x402.json"
          }
        },
        "security": [
          { "BearerAuth": [] }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "customer_id": { "type": "string", "example": "CARI-38491" },
                  "items": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "sku": { "type": "string", "example": "STK-LOGO-1002" },
                        "quantity": { "type": "integer", "example": 50 },
                        "unit_price": { "type": "number", "example": 85.50 }
                      },
                      "required": ["sku", "quantity"]
                    }
                  }
                },
                "required": ["customer_id", "items"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Order submitted and locked in ERP",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": { "type": "boolean", "example": true },
                    "order_number": { "type": "string", "example": "MR-2026-8491" },
                    "erp_ticket": { "type": "string", "example": "SIP-002914" },
                    "status": { "type": "string", "example": "reserved" }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT"
      },
      "x402Auth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-PAYMENT",
        "description": "x402 inline micropayment receipt token"
      }
    }
  }
}
