{
  "openapi": "3.1.0",
  "info": {
    "title": "Sender.ge SMS API",
    "version": "1.0.0",
    "description": "SMS sending, delivery status and balance API for Sender.ge.",
    "contact": { "name": "Sender.ge", "url": "https://sender.ge" }
  },
  "servers": [{ "url": "https://sender.ge/api", "description": "Production" }],
  "tags": [
    { "name": "Messages", "description": "Send and track SMS messages" },
    { "name": "Account", "description": "Account balance" }
  ],
  "paths": {
    "/send.php": {
      "post": {
        "tags": ["Messages"],
        "summary": "Send an SMS",
        "operationId": "sendSms",
        "requestBody": {
          "required": true,
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": { "$ref": "#/components/schemas/SendSmsRequest" }
            }
          }
        },
        "responses": {
          "200": { "description": "Request accepted", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/SendSmsResponse" } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "402": { "$ref": "#/components/responses/InsufficientBalance" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "503": { "$ref": "#/components/responses/Unavailable" }
        }
      }
    },
    "/callback.php": {
      "post": {
        "tags": ["Messages"],
        "summary": "Get delivery status",
        "operationId": "getDeliveryStatus",
        "requestBody": {
          "required": true,
          "content": { "application/x-www-form-urlencoded": { "schema": { "$ref": "#/components/schemas/DeliveryRequest" } } }
        },
        "responses": {
          "200": { "description": "Delivery status", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/DeliveryResponse" } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "503": { "$ref": "#/components/responses/Unavailable" }
        }
      }
    },
    "/getBalance.php": {
      "post": {
        "tags": ["Account"],
        "summary": "Get account balance",
        "operationId": "getBalance",
        "requestBody": {
          "required": true,
          "content": { "application/x-www-form-urlencoded": { "schema": { "$ref": "#/components/schemas/ApiKeyRequest" } } }
        },
        "responses": {
          "200": { "description": "Current balance", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/BalanceResponse" } } } },
          "404": { "description": "API key not found", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "ApiKeyRequest": {
        "type": "object",
        "required": ["apikey"],
        "properties": { "apikey": { "type": "string", "example": "YOUR_API_KEY", "writeOnly": true } }
      },
      "SendSmsRequest": {
        "allOf": [
          { "$ref": "#/components/schemas/ApiKeyRequest" },
          {
            "type": "object",
            "required": ["smsno", "destination", "content"],
            "properties": {
              "smsno": { "type": "integer", "enum": [1, 2], "example": 1 },
              "destination": { "type": "string", "pattern": "^[0-9]{9}$", "example": "555123456" },
              "content": { "type": "string", "example": "Hello from Sender.ge" },
              "priority": { "type": "integer", "enum": [1], "example": 1 }
            }
          }
        ]
      },
      "DeliveryRequest": {
        "allOf": [
          { "$ref": "#/components/schemas/ApiKeyRequest" },
          { "type": "object", "required": ["messageId"], "properties": { "messageId": { "type": "string", "example": "123KUxuhiGyDN3" } } }
        ]
      },
      "SendSmsResponse": {
        "type": "object",
        "properties": { "data": { "type": "array", "items": { "type": "object", "properties": { "messageId": { "type": "string" }, "statusId": { "type": "integer" }, "qnt": { "type": "integer" } } } } }
      },
      "DeliveryResponse": {
        "type": "object",
        "properties": { "data": { "type": "array", "items": { "type": "object", "properties": { "destination": { "type": "string" }, "statusId": { "type": "integer", "enum": [0, 1, 2] }, "timestamp": { "type": "string" } } } } }
      },
      "BalanceResponse": {
        "type": "object",
        "properties": { "data": { "type": "object", "properties": { "balance": { "type": "string", "example": "123.45" }, "overdraft": { "type": "string", "example": "0.00" } } } }
      },
      "Error": { "type": "object", "required": ["message"], "properties": { "message": { "type": "string" } } }
    },
    "responses": {
      "Unauthorized": { "description": "Invalid API key", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
      "InsufficientBalance": { "description": "Insufficient balance", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
      "Forbidden": { "description": "Access denied", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
      "Unavailable": { "description": "Service temporarily unavailable", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
    }
  }
}
