{
  "openapi": "3.1.0",
  "info": {
    "title": "wpkrypt API",
    "version": "1.0.0",
    "description": "Mesaj ve kampanya entegrasyonu, webhook yönetimi ve teslimat sözleşmesi.\n\nAPI anahtarını `Authorization: Bearer <API_KEY>` olarak gönderin. Anahtarlar panelden oluşturulur. Webhook ve API anahtarı yönetimi Sanctum panel oturumu gerektirir. Oturumla yazma istekleri için önce `GET /sanctum/csrf-cookie` çağrısı yapın ve XSRF-TOKEN çerezinin URL çözülmüş değerini X-XSRF-TOKEN başlığına koyun. Oturum çerezinin adı ortama göre değişebilir. JSON yanıtları için `Accept: application/json` kullanın. Hata metinleri `Accept-Language: tr` veya `en` ile değişir.\n\nAPI sınırı anahtar veya oturum kullanıcısı başına 120 istek/dakikadır. Webhook testine ek olarak kimlik doğrulama hız sınırı uygulanır. WhatsApp gönderim hızı farklıdır ve cihaz bazında sınırlanır.\n\nİş kuralı hatalarında HTTP durumu ve varsa `code` alanı kullanılır. Doğrulama hataları `errors` nesnesinde alan bazında döner. Asenkron mesaj hataları `data.error` alanındadır: `not_on_whatsapp`, `send_failed`, `device_logged_out`, `media_unavailable`, `queue_unavailable`, `campaign_cancelled`, `device_not_connected`, `recipient_opted_out`, `email_not_verified`, `package_expired` veya `insufficient_credits`. Kampanya iptali `campaign_cancelled` koduyla görünür. Webhook teslimat hataları: `url_not_allowed`, `connection_failed`, `timeout` ve `http_error`. Tanınmayan hata kodları için genel hata davranışı uygulayın."
  },
  "servers": [
    {
      "url": "/api/v1",
      "description": "Belgeyi sunan API ana makinesi."
    }
  ],
  "tags": [
    {
      "name": "Mesajlar"
    },
    {
      "name": "Kampanyalar"
    },
    {
      "name": "Webhook yönetimi"
    },
    {
      "name": "API anahtarları"
    }
  ],
  "paths": {
    "/messages": {
      "get": {
        "tags": [
          "Mesajlar"
        ],
        "operationId": "listMessages",
        "summary": "Mesajları listele",
        "security": [
          {
            "ApiKey": [
              "messages:read"
            ]
          },
          {
            "PanelSession": []
          }
        ],
        "x-api-key-ability": "messages:read",
        "parameters": [
          {
            "$ref": "#/components/parameters/Language"
          },
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1
            }
          },
          {
            "name": "per_page",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 25
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "scheduled",
                "queued",
                "sending",
                "sent",
                "delivered",
                "read",
                "failed",
                "received"
              ]
            }
          },
          {
            "name": "direction",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "in",
                "out"
              ]
            }
          },
          {
            "name": "phone",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 20
            }
          },
          {
            "name": "device_id",
            "in": "query",
            "schema": {
              "type": "string",
              "pattern": "^[0-7][0-9A-HJKMNP-TV-Z]{25}$"
            }
          },
          {
            "name": "campaign_id",
            "in": "query",
            "schema": {
              "type": "string",
              "pattern": "^[0-7][0-9A-HJKMNP-TV-Z]{25}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Mesaj listesi.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Message"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/Pagination"
                    }
                  },
                  "required": [
                    "data",
                    "meta"
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error401"
          },
          "403": {
            "$ref": "#/components/responses/Error403"
          },
          "422": {
            "$ref": "#/components/responses/Error422"
          },
          "429": {
            "$ref": "#/components/responses/Error429"
          },
          "500": {
            "$ref": "#/components/responses/Error500"
          }
        }
      },
      "post": {
        "tags": [
          "Mesajlar"
        ],
        "operationId": "sendMessage",
        "summary": "Mesaj gönder veya zamanla",
        "security": [
          {
            "ApiKey": [
              "messages:send"
            ]
          },
          {
            "PanelSession": [],
            "CsrfToken": []
          }
        ],
        "x-api-key-ability": "messages:send",
        "description": "device_id verilmezse en eski bağlı cihaz seçilir. E-posta doğrulaması ve aktif paket gerekir. Metin, görsel ve doküman mesajı başına 1 kredi. Zamanlanmış mesajın kredisi zamanı geldiğinde kuyruğa alınırken düşülür; gönderim limitleri uygulanır. Görseller JPEG, PNG, WebP (en fazla 5 MiB). Dokümanlar PDF, Word, Excel, PowerPoint, TXT, CSV ve ZIP (en fazla 16 MiB). Dosya içeriği ve uzantısı denetlenir.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Language"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TextMessageInput"
              },
              "examples": {
                "immediate": {
                  "value": {
                    "to": "+905550000000",
                    "text": "Merhaba"
                  }
                },
                "scheduled": {
                  "value": {
                    "to": "+905550000000",
                    "text": "Hatırlatma",
                    "scheduled_at": "2030-06-15T10:30:00+03:00"
                  }
                }
              }
            },
            "multipart/form-data": {
              "schema": {
                "$ref": "#/components/schemas/MediaMessageInput"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Mesaj kabul edildi; teslimat asenkrondur.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Message"
                    }
                  },
                  "required": [
                    "data"
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error401"
          },
          "402": {
            "$ref": "#/components/responses/Error402"
          },
          "403": {
            "$ref": "#/components/responses/Error403"
          },
          "404": {
            "$ref": "#/components/responses/Error404"
          },
          "413": {
            "$ref": "#/components/responses/Error413"
          },
          "419": {
            "$ref": "#/components/responses/Error419"
          },
          "422": {
            "$ref": "#/components/responses/Error422"
          },
          "429": {
            "$ref": "#/components/responses/Error429"
          },
          "500": {
            "$ref": "#/components/responses/Error500"
          }
        }
      }
    },
    "/messages/{message}": {
      "parameters": [
        {
          "name": "message",
          "in": "path",
          "schema": {
            "type": "string",
            "pattern": "^[0-7][0-9A-HJKMNP-TV-Z]{25}$"
          },
          "required": true
        }
      ],
      "get": {
        "tags": [
          "Mesajlar"
        ],
        "operationId": "getMessage",
        "summary": "Mesaj durumunu getir",
        "security": [
          {
            "ApiKey": [
              "messages:read"
            ]
          },
          {
            "PanelSession": []
          }
        ],
        "x-api-key-ability": "messages:read",
        "parameters": [
          {
            "$ref": "#/components/parameters/Language"
          }
        ],
        "responses": {
          "200": {
            "description": "Mesaj durumu.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Message"
                    }
                  },
                  "required": [
                    "data"
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error401"
          },
          "403": {
            "$ref": "#/components/responses/Error403"
          },
          "404": {
            "$ref": "#/components/responses/Error404"
          },
          "429": {
            "$ref": "#/components/responses/Error429"
          },
          "500": {
            "$ref": "#/components/responses/Error500"
          }
        }
      }
    },
    "/campaigns": {
      "get": {
        "tags": [
          "Kampanyalar"
        ],
        "operationId": "listCampaigns",
        "summary": "Kampanyaları listele",
        "security": [
          {
            "ApiKey": [
              "campaigns:read"
            ]
          },
          {
            "PanelSession": []
          }
        ],
        "x-api-key-ability": "campaigns:read",
        "parameters": [
          {
            "$ref": "#/components/parameters/Language"
          },
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Kampanyalar, sayfa başına 20 kayıt.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Campaign"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/Pagination"
                    }
                  },
                  "required": [
                    "data",
                    "meta"
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error401"
          },
          "403": {
            "$ref": "#/components/responses/Error403"
          },
          "429": {
            "$ref": "#/components/responses/Error429"
          },
          "500": {
            "$ref": "#/components/responses/Error500"
          }
        }
      },
      "post": {
        "tags": [
          "Kampanyalar"
        ],
        "operationId": "createCampaign",
        "summary": "Toplu gönderimi başlat",
        "security": [
          {
            "ApiKey": [
              "campaigns:write"
            ]
          },
          {
            "PanelSession": [],
            "CsrfToken": []
          }
        ],
        "x-api-key-ability": "campaigns:write",
        "description": "device_id verilmezse en eski bağlı cihaz seçilir. E-posta doğrulaması ve aktif paket gerekir. Görseller JPEG, PNG, WebP (en fazla 5 MiB). Dokümanlar PDF, Word, Excel, PowerPoint, TXT, CSV ve ZIP (en fazla 16 MiB). Dosya içeriği ve uzantısı denetlenir. Her alıcı için ayrı mesaj ve kredi hareketi oluşturulur. done, kampanyanın kuyruğa aktarımının tamamlandığını gösterir; teslimatı progress içinden izleyin.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Language"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "$ref": "#/components/schemas/CreateCampaignInput"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Kampanya kabul edildi.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Campaign"
                    }
                  },
                  "required": [
                    "data"
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error401"
          },
          "402": {
            "$ref": "#/components/responses/Error402"
          },
          "403": {
            "$ref": "#/components/responses/Error403"
          },
          "404": {
            "$ref": "#/components/responses/Error404"
          },
          "413": {
            "$ref": "#/components/responses/Error413"
          },
          "419": {
            "$ref": "#/components/responses/Error419"
          },
          "422": {
            "$ref": "#/components/responses/Error422"
          },
          "429": {
            "$ref": "#/components/responses/Error429"
          },
          "500": {
            "$ref": "#/components/responses/Error500"
          }
        }
      }
    },
    "/campaigns/preview": {
      "post": {
        "tags": [
          "Kampanyalar"
        ],
        "operationId": "previewCampaign",
        "summary": "Alıcı listesini ve eki önizle",
        "security": [
          {
            "ApiKey": [
              "campaigns:write"
            ]
          },
          {
            "PanelSession": [],
            "CsrfToken": []
          }
        ],
        "x-api-key-ability": "campaigns:write",
        "description": "E-posta doğrulaması gerekir. Yinelenen, geçersiz ve RET kaydı olan numaralar ayıklanır. Önizleme kredi düşmez.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Language"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "$ref": "#/components/schemas/CampaignInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Sayım, örnek mesaj ve kredi hesabı.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/CampaignPreview"
                    }
                  },
                  "required": [
                    "data"
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error401"
          },
          "403": {
            "$ref": "#/components/responses/Error403"
          },
          "413": {
            "$ref": "#/components/responses/Error413"
          },
          "419": {
            "$ref": "#/components/responses/Error419"
          },
          "422": {
            "$ref": "#/components/responses/Error422"
          },
          "429": {
            "$ref": "#/components/responses/Error429"
          },
          "500": {
            "$ref": "#/components/responses/Error500"
          }
        }
      }
    },
    "/campaigns/{campaign}": {
      "parameters": [
        {
          "name": "campaign",
          "in": "path",
          "schema": {
            "type": "string",
            "pattern": "^[0-7][0-9A-HJKMNP-TV-Z]{25}$"
          },
          "required": true
        }
      ],
      "get": {
        "tags": [
          "Kampanyalar"
        ],
        "operationId": "getCampaign",
        "summary": "Kampanya durumunu getir",
        "security": [
          {
            "ApiKey": [
              "campaigns:read"
            ]
          },
          {
            "PanelSession": []
          }
        ],
        "x-api-key-ability": "campaigns:read",
        "parameters": [
          {
            "$ref": "#/components/parameters/Language"
          }
        ],
        "responses": {
          "200": {
            "description": "Kampanya ve gönderim sayaçları.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Campaign"
                    }
                  },
                  "required": [
                    "data"
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error401"
          },
          "403": {
            "$ref": "#/components/responses/Error403"
          },
          "404": {
            "$ref": "#/components/responses/Error404"
          },
          "429": {
            "$ref": "#/components/responses/Error429"
          },
          "500": {
            "$ref": "#/components/responses/Error500"
          }
        }
      }
    },
    "/campaigns/{campaign}/cancel": {
      "parameters": [
        {
          "name": "campaign",
          "in": "path",
          "schema": {
            "type": "string",
            "pattern": "^[0-7][0-9A-HJKMNP-TV-Z]{25}$"
          },
          "required": true
        }
      ],
      "post": {
        "tags": [
          "Kampanyalar"
        ],
        "operationId": "cancelCampaign",
        "summary": "Bekleyen kampanya gönderimlerini iptal et",
        "security": [
          {
            "ApiKey": [
              "campaigns:write"
            ]
          },
          {
            "PanelSession": [],
            "CsrfToken": []
          }
        ],
        "x-api-key-ability": "campaigns:write",
        "description": "Gönderimi başlamamış mesajlar iptal edilir; ücretlendirilmiş bekleyen mesajların kredisi arka planda iade edilir. Gönderimi başlamış mesajlar devam edebilir. İstek tekrarlanabilir.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Language"
          }
        ],
        "responses": {
          "202": {
            "description": "İptal isteğinin ardından kampanya durumu.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Campaign"
                    }
                  },
                  "required": [
                    "data"
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error401"
          },
          "403": {
            "$ref": "#/components/responses/Error403"
          },
          "404": {
            "$ref": "#/components/responses/Error404"
          },
          "419": {
            "$ref": "#/components/responses/Error419"
          },
          "429": {
            "$ref": "#/components/responses/Error429"
          },
          "500": {
            "$ref": "#/components/responses/Error500"
          }
        }
      }
    },
    "/webhooks": {
      "get": {
        "tags": [
          "Webhook yönetimi"
        ],
        "operationId": "listWebhooks",
        "summary": "Webhook adreslerini listele",
        "security": [
          {
            "PanelSession": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Language"
          }
        ],
        "responses": {
          "200": {
            "description": "Webhook adresleri.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/WebhookEndpoint"
                      }
                    }
                  },
                  "required": [
                    "data"
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error401"
          },
          "403": {
            "$ref": "#/components/responses/Error403"
          },
          "429": {
            "$ref": "#/components/responses/Error429"
          },
          "500": {
            "$ref": "#/components/responses/Error500"
          }
        }
      },
      "post": {
        "tags": [
          "Webhook yönetimi"
        ],
        "operationId": "createWebhook",
        "summary": "Webhook adresi oluştur",
        "security": [
          {
            "PanelSession": [],
            "CsrfToken": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Language"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookInput"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Webhook ve yalnızca bu yanıtta verilen imza anahtarı.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/WebhookEndpoint"
                    },
                    "secret": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "data",
                    "secret"
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error401"
          },
          "403": {
            "$ref": "#/components/responses/Error403"
          },
          "419": {
            "$ref": "#/components/responses/Error419"
          },
          "422": {
            "$ref": "#/components/responses/Error422"
          },
          "429": {
            "$ref": "#/components/responses/Error429"
          },
          "500": {
            "$ref": "#/components/responses/Error500"
          }
        }
      }
    },
    "/webhooks/{webhook}": {
      "parameters": [
        {
          "name": "webhook",
          "in": "path",
          "schema": {
            "type": "integer",
            "minimum": 1
          },
          "required": true
        }
      ],
      "patch": {
        "tags": [
          "Webhook yönetimi"
        ],
        "operationId": "patchWebhook",
        "summary": "Webhook adresini güncelle",
        "security": [
          {
            "PanelSession": [],
            "CsrfToken": []
          }
        ],
        "description": "Her iki yöntem de url ve events alanlarını bekler.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Language"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Güncellenen webhook.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/WebhookEndpoint"
                    }
                  },
                  "required": [
                    "data"
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error401"
          },
          "403": {
            "$ref": "#/components/responses/Error403"
          },
          "404": {
            "$ref": "#/components/responses/Error404"
          },
          "419": {
            "$ref": "#/components/responses/Error419"
          },
          "422": {
            "$ref": "#/components/responses/Error422"
          },
          "429": {
            "$ref": "#/components/responses/Error429"
          },
          "500": {
            "$ref": "#/components/responses/Error500"
          }
        }
      },
      "put": {
        "tags": [
          "Webhook yönetimi"
        ],
        "operationId": "updateWebhook",
        "summary": "Webhook adresini güncelle",
        "security": [
          {
            "PanelSession": [],
            "CsrfToken": []
          }
        ],
        "description": "Her iki yöntem de url ve events alanlarını bekler.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Language"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Güncellenen webhook.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/WebhookEndpoint"
                    }
                  },
                  "required": [
                    "data"
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error401"
          },
          "403": {
            "$ref": "#/components/responses/Error403"
          },
          "404": {
            "$ref": "#/components/responses/Error404"
          },
          "419": {
            "$ref": "#/components/responses/Error419"
          },
          "422": {
            "$ref": "#/components/responses/Error422"
          },
          "429": {
            "$ref": "#/components/responses/Error429"
          },
          "500": {
            "$ref": "#/components/responses/Error500"
          }
        }
      },
      "delete": {
        "tags": [
          "Webhook yönetimi"
        ],
        "operationId": "deleteWebhook",
        "summary": "Webhook adresini sil",
        "security": [
          {
            "PanelSession": [],
            "CsrfToken": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Language"
          }
        ],
        "responses": {
          "204": {
            "description": "Silindi."
          },
          "401": {
            "$ref": "#/components/responses/Error401"
          },
          "403": {
            "$ref": "#/components/responses/Error403"
          },
          "404": {
            "$ref": "#/components/responses/Error404"
          },
          "419": {
            "$ref": "#/components/responses/Error419"
          },
          "429": {
            "$ref": "#/components/responses/Error429"
          },
          "500": {
            "$ref": "#/components/responses/Error500"
          }
        }
      }
    },
    "/webhooks/{webhook}/deliveries": {
      "parameters": [
        {
          "name": "webhook",
          "in": "path",
          "schema": {
            "type": "integer",
            "minimum": 1
          },
          "required": true
        }
      ],
      "get": {
        "tags": [
          "Webhook yönetimi"
        ],
        "operationId": "listWebhookDeliveries",
        "summary": "Son webhook denemelerini listele",
        "security": [
          {
            "PanelSession": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Language"
          }
        ],
        "responses": {
          "200": {
            "description": "En yeni 50 deneme. İstek gövdesi kayıt altına alınmaz.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/WebhookDelivery"
                      }
                    }
                  },
                  "required": [
                    "data"
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error401"
          },
          "403": {
            "$ref": "#/components/responses/Error403"
          },
          "404": {
            "$ref": "#/components/responses/Error404"
          },
          "429": {
            "$ref": "#/components/responses/Error429"
          },
          "500": {
            "$ref": "#/components/responses/Error500"
          }
        }
      }
    },
    "/webhooks/{webhook}/test": {
      "parameters": [
        {
          "name": "webhook",
          "in": "path",
          "schema": {
            "type": "integer",
            "minimum": 1
          },
          "required": true
        }
      ],
      "post": {
        "tags": [
          "Webhook yönetimi"
        ],
        "operationId": "testWebhook",
        "summary": "webhook.test olayını kuyruğa al",
        "security": [
          {
            "PanelSession": [],
            "CsrfToken": []
          }
        ],
        "description": "Pasif adreslerde de çalışır; olay abonelik listesine eklenmez. Sonucu teslimat geçmişinden izleyin.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Language"
          }
        ],
        "responses": {
          "202": {
            "description": "Tek denemelik test olayı kuyruğa alındı."
          },
          "401": {
            "$ref": "#/components/responses/Error401"
          },
          "403": {
            "$ref": "#/components/responses/Error403"
          },
          "404": {
            "$ref": "#/components/responses/Error404"
          },
          "419": {
            "$ref": "#/components/responses/Error419"
          },
          "429": {
            "$ref": "#/components/responses/Error429"
          },
          "500": {
            "$ref": "#/components/responses/Error500"
          }
        }
      }
    },
    "/webhooks/{webhook}/rotate-secret": {
      "parameters": [
        {
          "name": "webhook",
          "in": "path",
          "schema": {
            "type": "integer",
            "minimum": 1
          },
          "required": true
        }
      ],
      "post": {
        "tags": [
          "Webhook yönetimi"
        ],
        "operationId": "rotateWebhookSecret",
        "summary": "Webhook imza anahtarını yenile",
        "security": [
          {
            "PanelSession": [],
            "CsrfToken": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Language"
          }
        ],
        "responses": {
          "200": {
            "description": "Webhook ve yeni imza anahtarı. Önceki anahtar hemen geçersiz olur.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/WebhookEndpoint"
                    },
                    "secret": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "data",
                    "secret"
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error401"
          },
          "403": {
            "$ref": "#/components/responses/Error403"
          },
          "404": {
            "$ref": "#/components/responses/Error404"
          },
          "419": {
            "$ref": "#/components/responses/Error419"
          },
          "429": {
            "$ref": "#/components/responses/Error429"
          },
          "500": {
            "$ref": "#/components/responses/Error500"
          }
        }
      }
    },
    "/api-keys": {
      "get": {
        "tags": [
          "API anahtarları"
        ],
        "operationId": "listApiKeys",
        "summary": "API anahtarlarının izinlerini listele",
        "security": [
          {
            "PanelSession": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Language"
          }
        ],
        "responses": {
          "200": {
            "description": "Anahtar kayıtları.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ApiKey"
                      }
                    }
                  },
                  "required": [
                    "data"
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error401"
          },
          "403": {
            "$ref": "#/components/responses/Error403"
          },
          "429": {
            "$ref": "#/components/responses/Error429"
          },
          "500": {
            "$ref": "#/components/responses/Error500"
          }
        }
      },
      "post": {
        "tags": [
          "API anahtarları"
        ],
        "operationId": "createApiKey",
        "summary": "API anahtarı oluştur",
        "security": [
          {
            "PanelSession": [],
            "CsrfToken": []
          }
        ],
        "description": "Varsayılan izinler messages:send ve messages:read. bulk_access: true ile campaigns:read ve campaigns:write da verilir. Mevcut anahtarlara otomatik izin eklenmez.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Language"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ApiKeyInput"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Anahtar ve yalnızca bir kez gösterilen açık değeri.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/ApiKey"
                    },
                    "key": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "data",
                    "key"
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error401"
          },
          "403": {
            "$ref": "#/components/responses/Error403"
          },
          "404": {
            "$ref": "#/components/responses/Error404"
          },
          "419": {
            "$ref": "#/components/responses/Error419"
          },
          "422": {
            "$ref": "#/components/responses/Error422"
          },
          "429": {
            "$ref": "#/components/responses/Error429"
          },
          "500": {
            "$ref": "#/components/responses/Error500"
          }
        }
      }
    },
    "/api-keys/{api_key}": {
      "parameters": [
        {
          "name": "api_key",
          "in": "path",
          "schema": {
            "type": "integer",
            "minimum": 1
          },
          "required": true
        }
      ],
      "delete": {
        "tags": [
          "API anahtarları"
        ],
        "operationId": "deleteApiKey",
        "summary": "API anahtarını iptal et",
        "security": [
          {
            "PanelSession": [],
            "CsrfToken": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Language"
          }
        ],
        "responses": {
          "204": {
            "description": "Anahtar iptal edildi."
          },
          "401": {
            "$ref": "#/components/responses/Error401"
          },
          "403": {
            "$ref": "#/components/responses/Error403"
          },
          "404": {
            "$ref": "#/components/responses/Error404"
          },
          "419": {
            "$ref": "#/components/responses/Error419"
          },
          "429": {
            "$ref": "#/components/responses/Error429"
          },
          "500": {
            "$ref": "#/components/responses/Error500"
          }
        }
      }
    },
    "/messages/{message}/media": {
      "parameters": [
        {
          "name": "message",
          "in": "path",
          "schema": {
            "type": "string",
            "pattern": "^[0-7][0-9A-HJKMNP-TV-Z]{25}$"
          },
          "required": true
        }
      ],
      "get": {
        "tags": [
          "Mesajlar"
        ],
        "operationId": "downloadMessageMedia",
        "summary": "Gelen dosyayı indir",
        "description": "Kişinin gönderdiği görsel, video, ses veya dokümanı indirir. Yalnızca gelen mesajlar; dosya her zaman ek (attachment) olarak sunulur.",
        "security": [
          {
            "ApiKey": [
              "messages:read"
            ]
          },
          {
            "PanelSession": []
          }
        ],
        "x-api-key-ability": "messages:read",
        "responses": {
          "200": {
            "description": "Dosya.",
            "content": {
              "application/octet-stream": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error401"
          },
          "403": {
            "$ref": "#/components/responses/Error403"
          },
          "404": {
            "$ref": "#/components/responses/Error404"
          },
          "429": {
            "$ref": "#/components/responses/Error429"
          }
        }
      }
    }
  },
  "webhooks": {
    "eventDelivery": {
      "post": {
        "operationId": "receiveWebhookEvent",
        "summary": "İmzalı olay teslimatı",
        "description": "İmza, X-Wpkrypt-Timestamp başlığının metin değeri, bir nokta ve alınan ham JSON baytlarının birleşimi üzerinden hesaplanır. Anahtar olarak endpoint oluşturma veya yenileme yanıtındaki secret değerini kullanın.\n\n`X-Wpkrypt-Signature = sha256=<hex(HMAC-SHA256(secret, timestamp + \".\" + raw_body))>`\n\nJSON'u ayrıştırmadan önce ham gövdeyle hesaplayın ve imzayı sabit süreli karşılaştırın. Uygulamanıza uygun bir zaman sapması sınırı belirleyin (ör. 300 saniye). Zaman damgası her denemede yeniden oluşturulur. Bu nedenle aynı olayı birden fazla kez alabilecek şekilde işleyin; olay başlığı ve gövdedeki event alanı eşleşmelidir. 2xx başarılı kabul edilir. Yönlendirmeler izlenmez. Normal olaylar en fazla altı kez denenir; gecikmeler 10, 60, 300, 900 ve 3600 saniyedir. webhook.test bir kez denenir.\n\nPHP doğrulama örneği (`$rawBody` ham HTTP gövdesidir):\n\n```php\nif (!ctype_digit($timestamp) || abs(time() - (int) $timestamp) > 300) {\n    return false;\n}\n$expected = 'sha256='.hash_hmac('sha256', $timestamp.'.'.$rawBody, $secret);\nreturn hash_equals($expected, $signature);\n```\n",
        "security": [],
        "parameters": [
          {
            "name": "X-Wpkrypt-Event",
            "in": "header",
            "schema": {
              "type": "string",
              "enum": [
                "message.sent",
                "message.delivered",
                "message.read",
                "message.failed",
                "message.received",
                "device.connected",
                "device.disconnected",
                "webhook.test"
              ]
            },
            "required": true
          },
          {
            "name": "X-Wpkrypt-Timestamp",
            "in": "header",
            "schema": {
              "type": "string",
              "pattern": "^[0-9]+$"
            },
            "description": "Unix zamanı, saniye.",
            "required": true
          },
          {
            "name": "X-Wpkrypt-Signature",
            "in": "header",
            "schema": {
              "type": "string",
              "pattern": "^sha256=[0-9a-f]{64}$"
            },
            "required": true
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookEvent"
              },
              "examples": {
                "test": {
                  "value": {
                    "event": "webhook.test",
                    "created_at": "2026-12-06T12:00:00+00:00",
                    "data": {
                      "webhook_id": 1
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "Alıcı olayı başarıyla kabul etti."
          },
          "default": {
            "description": "Başarısız teslimat."
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKey": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "Sanctum personal access token",
        "description": "İşlemde listelenen kapsam, anahtarın Sanctum izni olmalıdır."
      },
      "PanelSession": {
        "type": "apiKey",
        "in": "cookie",
        "name": "wpkrypt_session",
        "description": "Panel oturumu. Gerçek çerez adı ortam ayarına göre değişebilir."
      },
      "CsrfToken": {
        "type": "apiKey",
        "in": "header",
        "name": "X-XSRF-TOKEN",
        "description": "XSRF-TOKEN çerezinin URL çözülmüş değeri."
      }
    },
    "parameters": {
      "Language": {
        "name": "Accept-Language",
        "in": "header",
        "schema": {
          "type": "string",
          "enum": [
            "tr",
            "en"
          ]
        },
        "description": "Varsayılan Türkçe."
      }
    },
    "responses": {
      "Error401": {
        "description": "Geçerli oturum veya API anahtarı gerekli.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Error402": {
        "description": "Yetersiz kredi.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "examples": {
              "insufficient_credits": {
                "value": {
                  "message": "Kredi yetersiz.",
                  "code": "insufficient_credits"
                }
              }
            }
          }
        }
      },
      "Error403": {
        "description": "İzin eksik, oturum gerekli, e-posta doğrulanmamış veya paket süresi dolmuş.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "examples": {
              "forbidden": {
                "value": {
                  "message": "Bu işlem için yetkiniz yok."
                }
              },
              "email_not_verified": {
                "value": {
                  "message": "E-posta adresinizi doğrulayın.",
                  "code": "email_not_verified"
                }
              },
              "package_expired": {
                "value": {
                  "message": "Paketinizin süresi doldu.",
                  "code": "package_expired"
                }
              }
            }
          }
        }
      },
      "Error404": {
        "description": "Kayıt bulunamadı veya başka bir hesaba ait.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Error413": {
        "description": "İstek gövdesi sunucunun yükleme sınırını aşıyor.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Error419": {
        "description": "Panel oturumunun CSRF doğrulaması başarısız.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Error422": {
        "description": "Doğrulama hatası veya reddedilen gönderim.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "examples": {
              "validation": {
                "value": {
                  "message": "Gönderim zamanı gelecekte olmalıdır.",
                  "errors": {
                    "scheduled_at": [
                      "Gönderim zamanı gelecekte olmalıdır."
                    ]
                  }
                }
              },
              "device_not_connected": {
                "value": {
                  "message": "Seçilen cihaz bağlı değil.",
                  "code": "device_not_connected"
                }
              },
              "recipient_opted_out": {
                "value": {
                  "message": "Alıcı mesaj almayı reddetti.",
                  "code": "recipient_opted_out"
                }
              }
            }
          }
        }
      },
      "Error429": {
        "description": "İstek sınırı aşıldı. Sunucu sağlarsa Retry-After başlığındaki süreyi bekleyin.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Error500": {
        "description": "Beklenmeyen sunucu hatası.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "message": {
            "type": "string"
          },
          "code": {
            "type": "string",
            "description": "Uygulama hata kodu, yalnızca bazı hatalarda döner."
          },
          "errors": {
            "type": "object",
            "additionalProperties": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          }
        },
        "required": [
          "message"
        ]
      },
      "Pagination": {
        "type": "object",
        "properties": {
          "current_page": {
            "type": "integer",
            "minimum": 1
          },
          "last_page": {
            "type": "integer",
            "minimum": 1
          },
          "total": {
            "type": "integer",
            "minimum": 0
          }
        },
        "required": [
          "current_page",
          "last_page",
          "total"
        ]
      },
      "Media": {
        "type": "object",
        "properties": {
          "name": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "mime": {
            "type": "string",
            "description": "Gelen dosyalarda içerikten tespit edilir."
          },
          "size": {
            "anyOf": [
              {
                "type": "integer",
                "minimum": 0
              },
              {
                "type": "null"
              }
            ]
          },
          "downloadable": {
            "type": "boolean",
            "description": "Gelen dosya saklanıyorsa true; GET /messages/{message}/media ile indirilir. Gelen dosyalar saklama süresi dolunca silinir."
          }
        },
        "required": [
          "name",
          "mime",
          "size"
        ]
      },
      "CampaignAttachment": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "type": {
            "type": "string",
            "enum": [
              "image",
              "document"
            ]
          },
          "mime": {
            "type": "string"
          }
        },
        "required": [
          "name",
          "type",
          "mime"
        ]
      },
      "Message": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^[0-7][0-9A-HJKMNP-TV-Z]{25}$"
          },
          "device_id": {
            "anyOf": [
              {
                "type": "string",
                "pattern": "^[0-7][0-9A-HJKMNP-TV-Z]{25}$"
              },
              {
                "type": "null"
              }
            ]
          },
          "campaign_id": {
            "anyOf": [
              {
                "type": "string",
                "pattern": "^[0-7][0-9A-HJKMNP-TV-Z]{25}$"
              },
              {
                "type": "null"
              }
            ]
          },
          "direction": {
            "type": "string",
            "enum": [
              "in",
              "out"
            ]
          },
          "phone": {
            "type": "string",
            "pattern": "^[1-9][0-9]{7,14}$",
            "description": "E.164, başında + olmadan."
          },
          "type": {
            "type": "string",
            "enum": [
              "text",
              "image",
              "video",
              "audio",
              "document"
            ]
          },
          "text": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "media": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/Media"
              },
              {
                "type": "null"
              }
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "scheduled",
              "queued",
              "sending",
              "sent",
              "delivered",
              "read",
              "failed",
              "received"
            ]
          },
          "error": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "credits": {
            "type": "integer",
            "minimum": 0
          },
          "scheduled_at": {
            "anyOf": [
              {
                "type": "string",
                "format": "date-time"
              },
              {
                "type": "null"
              }
            ]
          },
          "sent_at": {
            "anyOf": [
              {
                "type": "string",
                "format": "date-time"
              },
              {
                "type": "null"
              }
            ]
          },
          "delivered_at": {
            "anyOf": [
              {
                "type": "string",
                "format": "date-time"
              },
              {
                "type": "null"
              }
            ]
          },
          "read_at": {
            "anyOf": [
              {
                "type": "string",
                "format": "date-time"
              },
              {
                "type": "null"
              }
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "device_id",
          "campaign_id",
          "direction",
          "phone",
          "type",
          "text",
          "media",
          "status",
          "error",
          "credits",
          "scheduled_at",
          "sent_at",
          "delivered_at",
          "read_at",
          "created_at"
        ]
      },
      "TextMessageInput": {
        "type": "object",
        "properties": {
          "to": {
            "type": "string",
            "maxLength": 32,
            "examples": [
              "+90 555 000 00 00"
            ]
          },
          "device_id": {
            "anyOf": [
              {
                "type": "string",
                "pattern": "^[0-7][0-9A-HJKMNP-TV-Z]{25}$"
              },
              {
                "type": "null"
              }
            ]
          },
          "scheduled_at": {
            "anyOf": [
              {
                "type": "string",
                "format": "date-time",
                "description": "Saniye ve saat dilimi içeren gelecekte bir ISO 8601 zamanı. Örnek: 2030-06-15T10:30:00+03:00."
              },
              {
                "type": "null"
              }
            ]
          },
          "text": {
            "type": "string",
            "minLength": 1,
            "maxLength": 4096
          }
        },
        "required": [
          "to",
          "text"
        ]
      },
      "MediaMessageInput": {
        "type": "object",
        "properties": {
          "to": {
            "type": "string",
            "maxLength": 32
          },
          "device_id": {
            "anyOf": [
              {
                "type": "string",
                "pattern": "^[0-7][0-9A-HJKMNP-TV-Z]{25}$"
              },
              {
                "type": "null"
              }
            ]
          },
          "scheduled_at": {
            "anyOf": [
              {
                "type": "string",
                "format": "date-time"
              },
              {
                "type": "null"
              }
            ]
          },
          "text": {
            "anyOf": [
              {
                "type": "string",
                "maxLength": 1024
              },
              {
                "type": "null"
              }
            ]
          },
          "file": {
            "type": "string",
            "format": "binary"
          }
        },
        "required": [
          "to",
          "file"
        ]
      },
      "CampaignInput": {
        "type": "object",
        "properties": {
          "file": {
            "type": "string",
            "format": "binary",
            "description": "Alıcı listesi: CSV, TSV veya .xlsx; en fazla 2 MiB ve 10.000 satır. Başlıkta telefon sütunu bulunmalı. .xlsx için ilk sayfa okunur."
          },
          "attachment": {
            "type": "string",
            "format": "binary",
            "description": "Kampanyanın tüm mesajlarında kullanılacak isteğe bağlı görsel veya doküman."
          },
          "text": {
            "type": "string",
            "maxLength": 4096,
            "description": "{{sütun}} yer tutucuları desteklenir. Ek yoksa zorunlu. Ek varsa açıklama isteğe bağlıdır ve genişletilmiş metin RET satırı dahil en fazla 1.024 karakter olabilir."
          },
          "append_opt_out": {
            "type": "string",
            "enum": [
              "0",
              "1"
            ],
            "description": "Multipart değerleri. 1 gönderilen metne alıcının listeden çıkma yönergesini ekler."
          }
        },
        "required": [
          "file"
        ],
        "allOf": [
          {
            "if": {
              "required": [
                "attachment"
              ]
            },
            "then": {
              "properties": {
                "text": {
                  "maxLength": 1024
                }
              }
            },
            "else": {
              "required": [
                "text"
              ]
            }
          }
        ]
      },
      "CreateCampaignInput": {
        "allOf": [
          {
            "$ref": "#/components/schemas/CampaignInput"
          },
          {
            "type": "object",
            "properties": {
              "name": {
                "type": "string",
                "minLength": 1,
                "maxLength": 100
              },
              "device_id": {
                "anyOf": [
                  {
                    "type": "string",
                    "pattern": "^[0-7][0-9A-HJKMNP-TV-Z]{25}$"
                  },
                  {
                    "type": "null"
                  }
                ]
              }
            },
            "required": [
              "name"
            ]
          }
        ]
      },
      "CampaignPreview": {
        "type": "object",
        "properties": {
          "columns": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "phone_column": {
            "type": "string"
          },
          "recipients": {
            "type": "integer",
            "minimum": 0
          },
          "duplicates": {
            "type": "integer",
            "minimum": 0
          },
          "opted_out": {
            "type": "integer",
            "minimum": 0
          },
          "invalid": {
            "type": "integer",
            "minimum": 0
          },
          "invalid_rows": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "row": {
                  "type": "integer",
                  "minimum": 1
                },
                "reason": {
                  "type": "string"
                }
              },
              "required": [
                "row",
                "reason"
              ]
            }
          },
          "sample": {
            "anyOf": [
              {
                "type": "object",
                "properties": {
                  "phone": {
                    "type": "string",
                    "pattern": "^[1-9][0-9]{7,14}$",
                    "description": "E.164, başında + olmadan."
                  },
                  "body": {
                    "type": "string"
                  }
                },
                "required": [
                  "phone",
                  "body"
                ]
              },
              {
                "type": "null"
              }
            ]
          },
          "attachment": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/CampaignAttachment"
              },
              {
                "type": "null"
              }
            ]
          },
          "credits_needed": {
            "type": "integer",
            "minimum": 0
          },
          "balance": {
            "type": "integer",
            "minimum": 0
          }
        },
        "required": [
          "columns",
          "phone_column",
          "recipients",
          "duplicates",
          "opted_out",
          "invalid",
          "invalid_rows",
          "sample",
          "attachment",
          "credits_needed",
          "balance"
        ]
      },
      "Campaign": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^[0-7][0-9A-HJKMNP-TV-Z]{25}$"
          },
          "name": {
            "type": "string"
          },
          "device": {
            "anyOf": [
              {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "string",
                    "pattern": "^[0-7][0-9A-HJKMNP-TV-Z]{25}$"
                  },
                  "name": {
                    "type": "string"
                  }
                },
                "required": [
                  "id",
                  "name"
                ]
              },
              {
                "type": "null"
              }
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "queueing",
              "done",
              "stopped"
            ]
          },
          "error": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "can_cancel": {
            "type": "boolean"
          },
          "attachment": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/CampaignAttachment"
              },
              {
                "type": "null"
              }
            ]
          },
          "total": {
            "type": "integer",
            "minimum": 0
          },
          "skipped": {
            "type": "object",
            "properties": {
              "duplicates": {
                "type": "integer",
                "minimum": 0
              },
              "opted_out": {
                "type": "integer",
                "minimum": 0
              },
              "invalid": {
                "type": "integer",
                "minimum": 0
              }
            },
            "required": [
              "duplicates",
              "opted_out",
              "invalid"
            ]
          },
          "progress": {
            "type": "object",
            "properties": {
              "pending": {
                "type": "integer",
                "minimum": 0
              },
              "sent": {
                "type": "integer",
                "minimum": 0
              },
              "delivered": {
                "type": "integer",
                "minimum": 0
              },
              "read": {
                "type": "integer",
                "minimum": 0
              },
              "failed": {
                "type": "integer",
                "minimum": 0
              }
            },
            "required": [
              "pending",
              "sent",
              "delivered",
              "read",
              "failed"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "name",
          "device",
          "status",
          "error",
          "can_cancel",
          "attachment",
          "total",
          "skipped",
          "progress",
          "created_at"
        ]
      },
      "WebhookInput": {
        "type": "object",
        "properties": {
          "url": {
            "type": "string",
            "format": "uri",
            "maxLength": 2048,
            "description": "Canlı ortamda herkese açık HTTPS adresi; özel ağ adresleri reddedilir."
          },
          "events": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "message.sent",
                "message.delivered",
                "message.read",
                "message.failed",
                "message.received",
                "device.connected",
                "device.disconnected"
              ]
            },
            "minItems": 1
          },
          "active": {
            "type": "boolean"
          }
        },
        "required": [
          "url",
          "events"
        ]
      },
      "WebhookEndpoint": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "minimum": 1
          },
          "url": {
            "type": "string",
            "format": "uri"
          },
          "events": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "message.sent",
                "message.delivered",
                "message.read",
                "message.failed",
                "message.received",
                "device.connected",
                "device.disconnected"
              ]
            }
          },
          "active": {
            "type": "boolean"
          },
          "last_delivery_at": {
            "anyOf": [
              {
                "type": "string",
                "format": "date-time"
              },
              {
                "type": "null"
              }
            ]
          },
          "last_status": {
            "anyOf": [
              {
                "type": "integer",
                "minimum": 0
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "required": [
          "id",
          "url",
          "events",
          "active",
          "last_delivery_at",
          "last_status"
        ]
      },
      "WebhookDelivery": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "minimum": 1
          },
          "event": {
            "type": "string",
            "enum": [
              "message.sent",
              "message.delivered",
              "message.read",
              "message.failed",
              "message.received",
              "device.connected",
              "device.disconnected",
              "webhook.test"
            ]
          },
          "message_id": {
            "anyOf": [
              {
                "type": "string",
                "pattern": "^[0-7][0-9A-HJKMNP-TV-Z]{25}$"
              },
              {
                "type": "null"
              }
            ]
          },
          "attempt": {
            "type": "integer",
            "minimum": 1
          },
          "status_code": {
            "anyOf": [
              {
                "type": "integer",
                "minimum": 1
              },
              {
                "type": "null"
              }
            ]
          },
          "error": {
            "anyOf": [
              {
                "type": "string",
                "enum": [
                  "timeout",
                  "connection_failed",
                  "http_error",
                  "url_not_allowed"
                ]
              },
              {
                "type": "null"
              }
            ]
          },
          "duration_ms": {
            "type": "integer",
            "minimum": 0
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "event",
          "message_id",
          "attempt",
          "status_code",
          "error",
          "duration_ms",
          "created_at"
        ]
      },
      "MessageEventData": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^[0-7][0-9A-HJKMNP-TV-Z]{25}$"
          },
          "device_id": {
            "anyOf": [
              {
                "type": "string",
                "pattern": "^[0-7][0-9A-HJKMNP-TV-Z]{25}$"
              },
              {
                "type": "null"
              }
            ]
          },
          "direction": {
            "type": "string",
            "enum": [
              "in",
              "out"
            ]
          },
          "phone": {
            "type": "string",
            "pattern": "^[1-9][0-9]{7,14}$",
            "description": "E.164, başında + olmadan."
          },
          "type": {
            "type": "string",
            "enum": [
              "text",
              "image",
              "video",
              "audio",
              "document"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "scheduled",
              "queued",
              "sending",
              "sent",
              "delivered",
              "read",
              "failed",
              "received"
            ]
          },
          "error": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "text": {
            "anyOf": [
              {
                "type": "string",
                "description": "Yalnızca gelen mesajın metni; giden mesajlarda null."
              },
              {
                "type": "null"
              }
            ]
          },
          "media": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/IncomingMedia"
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "required": [
          "id",
          "device_id",
          "direction",
          "phone",
          "type",
          "status",
          "error",
          "text"
        ]
      },
      "WebhookEvent": {
        "oneOf": [
          {
            "type": "object",
            "properties": {
              "event": {
                "type": "string",
                "enum": [
                  "message.sent",
                  "message.delivered",
                  "message.read",
                  "message.failed",
                  "message.received"
                ]
              },
              "created_at": {
                "type": "string",
                "format": "date-time"
              },
              "data": {
                "$ref": "#/components/schemas/MessageEventData"
              }
            },
            "required": [
              "event",
              "created_at",
              "data"
            ]
          },
          {
            "type": "object",
            "properties": {
              "event": {
                "type": "string",
                "enum": [
                  "device.connected"
                ]
              },
              "created_at": {
                "type": "string",
                "format": "date-time"
              },
              "data": {
                "type": "object",
                "properties": {
                  "device_id": {
                    "type": "string",
                    "pattern": "^[0-7][0-9A-HJKMNP-TV-Z]{25}$"
                  },
                  "phone": {
                    "anyOf": [
                      {
                        "type": "string",
                        "pattern": "^[1-9][0-9]{7,14}$",
                        "description": "E.164, başında + olmadan."
                      },
                      {
                        "type": "null"
                      }
                    ]
                  }
                },
                "required": [
                  "device_id",
                  "phone"
                ]
              }
            },
            "required": [
              "event",
              "created_at",
              "data"
            ]
          },
          {
            "type": "object",
            "properties": {
              "event": {
                "type": "string",
                "enum": [
                  "device.disconnected"
                ]
              },
              "created_at": {
                "type": "string",
                "format": "date-time"
              },
              "data": {
                "type": "object",
                "properties": {
                  "device_id": {
                    "type": "string",
                    "pattern": "^[0-7][0-9A-HJKMNP-TV-Z]{25}$"
                  },
                  "logged_out": {
                    "type": "boolean"
                  }
                },
                "required": [
                  "device_id",
                  "logged_out"
                ]
              }
            },
            "required": [
              "event",
              "created_at",
              "data"
            ]
          },
          {
            "type": "object",
            "properties": {
              "event": {
                "type": "string",
                "enum": [
                  "webhook.test"
                ]
              },
              "created_at": {
                "type": "string",
                "format": "date-time"
              },
              "data": {
                "type": "object",
                "properties": {
                  "webhook_id": {
                    "type": "integer",
                    "minimum": 1
                  }
                },
                "required": [
                  "webhook_id"
                ]
              }
            },
            "required": [
              "event",
              "created_at",
              "data"
            ]
          }
        ]
      },
      "ApiKey": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "minimum": 1
          },
          "name": {
            "type": "string"
          },
          "domain_id": {
            "anyOf": [
              {
                "type": "integer",
                "minimum": 1
              },
              {
                "type": "null"
              }
            ]
          },
          "abilities": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "messages:send",
                "messages:read",
                "campaigns:read",
                "campaigns:write"
              ]
            }
          },
          "last_used_at": {
            "anyOf": [
              {
                "type": "string",
                "format": "date-time"
              },
              {
                "type": "null"
              }
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "name",
          "domain_id",
          "abilities",
          "last_used_at",
          "created_at"
        ]
      },
      "ApiKeyInput": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "domain_id": {
            "anyOf": [
              {
                "type": "integer",
                "minimum": 1
              },
              {
                "type": "null"
              }
            ]
          },
          "bulk_access": {
            "type": "boolean",
            "default": false,
            "description": "true ise campaigns:read ve campaigns:write kapsamları eklenir."
          }
        },
        "required": [
          "name"
        ]
      },
      "IncomingMedia": {
        "type": "object",
        "description": "Kişinin gönderdiği dosya. Dosya alınamadıysa url null olur ve error alanı media_unavailable veya media_too_large olur.",
        "properties": {
          "name": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "mime": {
            "type": "string"
          },
          "size": {
            "anyOf": [
              {
                "type": "integer",
                "minimum": 0
              },
              {
                "type": "null"
              }
            ]
          },
          "url": {
            "anyOf": [
              {
                "type": "string",
                "format": "uri",
                "description": "İmzalı, 7 gün geçerli indirme adresi."
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "required": [
          "name",
          "mime",
          "size",
          "url"
        ]
      }
    }
  }
}
