{
  "openapi": "3.0.3",
  "info": {
    "title": "Wapedia Public API",
    "description": "WhatsApp Cloud API platform for Indonesian businesses. Path prefix /v1; semantic version tracks changelog.",
    "version": "1.0.0",
    "contact": {
      "name": "Wapedia",
      "url": "https://wapedia.id/docs/"
    }
  },
  "servers": [
    {
      "url": "https://api.wapedia.id",
      "description": "Production"
    },
    {
      "url": "http://localhost:8080",
      "description": "Local"
    }
  ],
  "tags": [
    { "name": "Messages" },
    { "name": "Media" },
    { "name": "Wallet" },
    { "name": "Meta" }
  ],
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Tenant API key"
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": { "type": "string" }
        },
        "required": ["error"]
      },
      "SendTextMessage": {
        "type": "object",
        "required": ["to", "body"],
        "properties": {
          "to": { "type": "string", "example": "6281234567890" },
          "type": { "type": "string", "enum": ["text"], "default": "text" },
          "body": { "type": "string" },
          "phone_number_id": { "type": "string" },
          "campaign_name": { "type": "string" }
        }
      },
      "OutboundAccepted": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "format": "uuid" },
          "status": { "type": "string", "example": "queued" },
          "type": { "type": "string" },
          "to": { "type": "string" }
        }
      }
    }
  },
  "security": [{ "BearerAuth": [] }],
  "paths": {
    "/v1/messages": {
      "post": {
        "tags": ["Messages"],
        "summary": "Send a WhatsApp message",
        "operationId": "sendMessage",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/SendTextMessage" }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Queued",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/OutboundAccepted" }
              }
            }
          },
          "400": {
            "description": "Validation or billing gate",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/Error" }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/Error" }
              }
            }
          }
        }
      }
    },
    "/v1/messages/{id}": {
      "get": {
        "tags": ["Messages"],
        "summary": "Get outbound message status",
        "operationId": "getMessage",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": { "type": "string", "format": "uuid" }
          }
        ],
        "responses": {
          "200": { "description": "Outbound message" },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/Error" }
              }
            }
          }
        }
      }
    },
    "/v1/messages/inbound": {
      "get": {
        "tags": ["Messages"],
        "summary": "List inbound messages",
        "operationId": "listInbound",
        "parameters": [
          { "name": "limit", "in": "query", "schema": { "type": "integer", "default": 50 } },
          { "name": "offset", "in": "query", "schema": { "type": "integer", "default": 0 } },
          { "name": "from", "in": "query", "schema": { "type": "string" } },
          { "name": "type", "in": "query", "schema": { "type": "string" } }
        ],
        "responses": {
          "200": { "description": "Inbound list" }
        }
      }
    },
    "/v1/messages/outbound": {
      "get": {
        "tags": ["Messages"],
        "summary": "List outbound messages",
        "operationId": "listOutbound",
        "parameters": [
          { "name": "limit", "in": "query", "schema": { "type": "integer", "default": 50 } },
          { "name": "offset", "in": "query", "schema": { "type": "integer", "default": 0 } },
          { "name": "to", "in": "query", "schema": { "type": "string" } }
        ],
        "responses": {
          "200": { "description": "Outbound list" }
        }
      }
    },
    "/v1/media": {
      "post": {
        "tags": ["Media"],
        "summary": "Upload media (max 16MB)",
        "operationId": "uploadMedia",
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": ["file"],
                "properties": {
                  "file": { "type": "string", "format": "binary" },
                  "mime_type": { "type": "string" },
                  "phone_number_id": { "type": "string" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Uploaded",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "media_id": { "type": "string" }
                  }
                }
              }
            }
          },
          "413": {
            "description": "File too large",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/Error" }
              }
            }
          }
        }
      }
    },
    "/v1/wallet": {
      "get": {
        "tags": ["Wallet"],
        "summary": "Get wallet balance",
        "operationId": "getWalletBalance",
        "responses": {
          "200": { "description": "Balance" }
        }
      }
    },
    "/v1/wallet/pricing": {
      "get": {
        "tags": ["Wallet"],
        "summary": "Overage debit pricing table",
        "operationId": "getWalletPricing",
        "responses": {
          "200": { "description": "Pricing categories" }
        }
      }
    },
    "/v1/wallet/transactions": {
      "get": {
        "tags": ["Wallet"],
        "summary": "List wallet transactions",
        "operationId": "listWalletTransactions",
        "parameters": [
          { "name": "limit", "in": "query", "schema": { "type": "integer", "default": 50 } }
        ],
        "responses": {
          "200": { "description": "Transactions" }
        }
      }
    },
    "/v1/subscription": {
      "get": {
        "tags": ["Wallet"],
        "summary": "Current subscription plan",
        "operationId": "getSubscription",
        "responses": {
          "200": { "description": "Plan" }
        }
      }
    },
    "/v1/usage": {
      "get": {
        "tags": ["Wallet"],
        "summary": "Monthly usage summary",
        "operationId": "getUsage",
        "responses": {
          "200": { "description": "Usage" }
        }
      }
    },
    "/v1/meta/oauth/url": {
      "get": {
        "tags": ["Meta"],
        "summary": "Embedded Signup OAuth URL",
        "operationId": "getMetaOAuthURL",
        "responses": {
          "200": { "description": "OAuth URL payload" }
        }
      }
    },
    "/v1/openapi.json": {
      "get": {
        "tags": ["Meta"],
        "summary": "This OpenAPI document",
        "operationId": "getOpenAPI",
        "security": [],
        "responses": {
          "200": {
            "description": "OpenAPI 3 JSON",
            "content": {
              "application/json": {
                "schema": { "type": "object" }
              }
            }
          }
        }
      }
    }
  }
}
