{
  "openapi": "3.1.0",
  "info": {
    "title": "Başlıklı SMS REST API & Remote MCP",
    "version": "1.2.0",
    "description": "Türkiye B2B Başlıklı SMS, yerleşik OTP doğrulama, SMS RET yönetimi, Webhook bildirimleri ve Streamable HTTP MCP sunucusu için resmi OpenAPI 3.1 sözleşmesi.",
    "contact": {
      "name": "Ankara Yazılım® Teknik Destek",
      "url": "https://basliklisms.com/api-referansi/",
      "email": "destek@basliklisms.com"
    }
  },
  "servers": [
    {
      "url": "https://basliklisms.com",
      "description": "Canlı Üretim Sunucusu"
    }
  ],
  "security": [{ "ApiKeyAuth": [] }],
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key",
        "description": "Panel > API Ayarları bölümünden oluşturulan bsl_live_... anahtarı."
      }
    },
    "parameters": {
      "IdempotencyKey": {
        "name": "Idempotency-Key",
        "in": "header",
        "required": false,
        "schema": { "type": "string", "maxLength": 128 },
        "description": "Aynı isteğin ağ tekrarlarında ikinci kez SMS/OTP göndermesini önler."
      }
    },
    "schemas": {
      "ApiError": {
        "type": "object",
        "required": ["success", "error"],
        "properties": {
          "success": { "type": "boolean", "const": false },
          "error": {
            "type": "object",
            "required": ["code", "message"],
            "properties": {
              "code": { "type": "string" },
              "message": { "type": "string" },
              "providerCode": { "type": "string" },
              "providerDescription": { "type": "string" },
              "remainingAttempts": { "type": "integer" }
            }
          }
        }
      }
    }
  },
  "paths": {
    "/api/v1/sms/send": {
      "post": {
        "summary": "Serbest metinli Başlıklı SMS gönder",
        "description": "Onaylı gönderici başlığı ile 1–1.000 alıcıya SMS gönderir. ANKARA YZLM genel başlığı kabul edilmez (403 PLATFORM_HEADER_OTP_ONLY).",
        "parameters": [{ "$ref": "#/components/parameters/IdempotencyKey" }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["message"],
                "properties": {
                  "header": { "type": "string", "minLength": 3, "maxLength": 11 },
                  "message": { "type": "string", "minLength": 1, "maxLength": 918 },
                  "recipients": { "type": "array", "items": { "type": "string" }, "maxItems": 1000 },
                  "phone": { "type": "string" },
                  "commercial": { "type": "boolean", "default": false }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Gönderim tamamlandı" },
          "400": { "description": "Geçersiz istek" },
          "401": { "description": "Kimlik doğrulama hatası" },
          "402": { "description": "Yetersiz kredi" },
          "403": { "description": "Yetkisiz başlık" },
          "409": { "description": "Başlık tanımsız veya devam eden idempotency kilidi" },
          "413": { "description": "Tek istekte 1.000 alıcı sınırı aşıldı" },
          "424": { "description": "Sağlayıcı hatası (kredi otomatik iade edilir)" },
          "429": { "description": "Hız limiti (Retry-After ile)" },
          "503": { "description": "Servis hazır değil" }
        }
      }
    },
    "/api/v1/balance": {
      "get": {
        "summary": "Kalan SMS kredisini sorgula",
        "responses": {
          "200": { "description": "Güncel kredi ve kullanım özeti" },
          "401": { "description": "Kimlik doğrulama hatası" }
        }
      }
    },
    "/api/v1/otp/send": {
      "post": {
        "summary": "Tek kullanımlık OTP SMS doğrulama kodu gönder",
        "parameters": [{ "$ref": "#/components/parameters/IdempotencyKey" }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["phone"],
                "properties": {
                  "phone": { "type": "string" },
                  "brand": { "type": "string", "maxLength": 32 },
                  "templateId": { "type": "string", "default": "giris-dogrulama" },
                  "ttlSeconds": { "type": "integer", "minimum": 60, "maximum": 600, "default": 180 },
                  "length": { "type": "integer", "enum": [4, 6, 8], "default": 6 },
                  "header": { "type": "string" }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "OTP gönderildi" },
          "402": { "description": "Yetersiz kredi" },
          "429": { "description": "Numara başına 45sn / saatlik 5 OTP sınırı" }
        }
      }
    },
    "/api/v1/otp/verify": {
      "post": {
        "summary": "OTP doğrulama kodunu kontrol et",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["code"],
                "properties": {
                  "id": { "type": "string" },
                  "phone": { "type": "string" },
                  "code": { "type": "string", "minLength": 4, "maxLength": 8 }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Doğrulama sonucu" },
          "400": { "description": "Hatalı kod (remainingAttempts döner)" },
          "410": { "description": "Kod süresi dolmuş veya kullanılmış" },
          "423": { "description": "5 hatalı deneme sonrası kod kilitlendi" }
        }
      }
    },
    "/api/v1/otp/logs": {
      "get": {
        "summary": "OTP gönderim kayıtlarını listele",
        "responses": { "200": { "description": "Sayfalı OTP gönderim özetleri" } }
      }
    },
    "/api/v1/opt-outs": {
      "get": {
        "summary": "SMS RET (opt-out) listesini getir",
        "parameters": [
          { "name": "page", "in": "query", "schema": { "type": "integer", "default": 1 } },
          { "name": "limit", "in": "query", "schema": { "type": "integer", "maximum": 200, "default": 50 } }
        ],
        "responses": { "200": { "description": "RET kayıtları" } }
      },
      "post": {
        "summary": "RET listesine numara ekle",
        "responses": { "200": { "description": "Numaralar eklendi" } }
      },
      "delete": {
        "summary": "RET listesinden numara çıkar",
        "responses": { "200": { "description": "Numara silindi" } }
      }
    },
    "/api/v1/webhooks": {
      "get": {
        "summary": "Teslimat ve düşük bakiye webhook ayarlarını oku (oturum gerekir)",
        "responses": { "200": { "description": "Webhook yapılandırması" } }
      },
      "put": {
        "summary": "HMAC-SHA256 imzalı HTTPS webhook hedefini kaydet (oturum gerekir)",
        "responses": { "200": { "description": "Güncellendi" } }
      },
      "delete": {
        "summary": "Webhook yapılandırmasını kaldır (oturum gerekir)",
        "responses": { "200": { "description": "Kaldırıldı" } }
      }
    },
    "/api/v1/webhooks/test": {
      "post": {
        "summary": "Tanımlı webhook URL'sine test olayı (webhook.test) gönder (oturum gerekir)",
        "responses": { "200": { "description": "Test sonucu" } }
      }
    },
    "/api/v1/api-keys/{id}/rotate": {
      "post": {
        "summary": "API anahtarını atomik olarak döndür (oturum gerekir)",
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }],
        "responses": { "200": { "description": "Yeni anahtar üretildi, eski anahtar iptal edildi" } }
      }
    },
    "/api/v1/outbox": {
      "get": {
        "summary": "Gönderim geçmişini sayfalı listele",
        "parameters": [
          { "name": "page", "in": "query", "schema": { "type": "integer", "default": 1 } },
          { "name": "limit", "in": "query", "schema": { "type": "integer", "maximum": 200, "default": 50 } }
        ],
        "responses": {
          "200": { "description": "Gönderim kayıtları" },
          "401": { "description": "Kimlik doğrulama hatası" }
        }
      }
    },
    "/api/v1/outbox/{id}/report": {
      "get": {
        "summary": "Gönderim kaydı için canlı iletim mutabakat raporu önizlemesi",
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }],
        "responses": {
          "200": { "description": "Kayıt detayı ve operatör segment mutabakat özeti" },
          "401": { "description": "Kimlik doğrulama hatası" },
          "404": { "description": "Kayıt bulunamadı" }
        }
      }
    },
    "/api/v1/outbox/export": {
      "get": {
        "summary": "9 sütunlu CSV gönderim raporu indir (Kayıt No ve Operatör İş No dahil)",
        "responses": {
          "200": { "description": "text/csv akışı" },
          "401": { "description": "Kimlik doğrulama hatası" }
        }
      }
    },
    "/v3/reports/status/{id}": {
      "get": {
        "summary": "İstek ID veya operatorJobId ile gönderim durumunu sorgula",
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }],
        "responses": {
          "200": { "description": "Durum özeti" },
          "401": { "description": "Kimlik doğrulama hatası" },
          "404": { "description": "Kayıt bulunamadı" }
        }
      }
    },
    "/api/mcp": {
      "post": {
        "summary": "Remote Streamable HTTP MCP (JSON-RPC 2.0)",
        "description": "calculate_sms_segments, check_sender_header, list_packages, get_balance, send_sms, send_otp, verify_otp ve manage_opt_outs araçlarını sunar.",
        "security": [],
        "responses": { "200": { "description": "JSON-RPC 2.0 yanıtı" } }
      }
    }
  }
}
