{
    "openapi": "3.1.0",
    "info": {
        "title": "DIAMOND GATEWAY - REST & AI Agent API (GPTs / Gemini / Claude / CRM)",
        "version": "1.1.0",
        "description": "Bagimsiz Android SIM SMS Gateway API. ChatGPT Custom GPT Actions, Google Gemini Function Calling, Claude MCP ve kurumsal CRM sistemleri ile dogrudan entegrasyon saglar. Kimlik dogrulama icin X-API-Key veya Authorization: Bearer <dg_live_...> kullanilir.",
        "contact": {
            "name": "DIAMOND GATEWAY Destek ve Basvuru Hatti",
            "phone": "+905461000112",
            "url": "https://gateway.tomrispartners.org.tr"
        }
    },
    "servers": [
        {
            "url": "https://gateway.tomrispartners.org.tr/api",
            "description": "Canli DIAMOND GATEWAY API Sunucusu"
        }
    ],
    "components": {
        "securitySchemes": {
            "ApiKeyHeader": {
                "type": "apiKey",
                "in": "header",
                "name": "X-API-Key",
                "description": "Musteri API Anahtari (dg_live_...)"
            },
            "BearerAuth": {
                "type": "http",
                "scheme": "bearer",
                "description": "ChatGPT Custom GPT / AI Agent Bearer API Anahtari (dg_live_...)"
            }
        }
    },
    "security": [
        {
            "ApiKeyHeader": []
        },
        {
            "BearerAuth": []
        }
    ],
    "paths": {
        "/v1/ai/overview": {
            "get": {
                "operationId": "getGatewayOverview",
                "summary": "Isletme SMS kotasi, bugunku gonderimler, rehber sayisi ve bagli Android SIM cihazlarin durumunu getirir.",
                "responses": {
                    "200": {
                        "description": "Isletme ve cihaz durumu ozeti"
                    }
                }
            }
        },
        "/v1/ai/send-sms": {
            "post": {
                "operationId": "sendSmsWithAi",
                "summary": "Bagli Android SIM cihazi uzerinden tekil SMS gonderir (Idempotency anahtari otomatik uretilir).",
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "required": [
                                    "to",
                                    "body"
                                ],
                                "properties": {
                                    "to": {
                                        "type": "string",
                                        "description": "E.164 formatinda alici telefon numarasi (ornek: +905461000112)"
                                    },
                                    "body": {
                                        "type": "string",
                                        "description": "Gonderilecek SMS metni"
                                    },
                                    "idempotency_key": {
                                        "type": "string",
                                        "description": "Istege bagli cift gonderim koruma anahtari"
                                    },
                                    "is_marketing": {
                                        "type": "boolean",
                                        "description": "Ticari/kampanya mesaji mi? (Varsayilan: false)"
                                    }
                                }
                            }
                        }
                    }
                },
                "responses": {
                    "202": {
                        "description": "SMS kuyruga alindi"
                    }
                }
            }
        },
        "/v1/messages": {
            "get": {
                "operationId": "listMessages",
                "summary": "Giden ve gelen SMS kayitlarini filtreleyerek listeler.",
                "parameters": [
                    {
                        "name": "direction",
                        "in": "query",
                        "schema": {
                            "type": "string",
                            "enum": [
                                "outbound",
                                "inbound"
                            ]
                        }
                    },
                    {
                        "name": "status",
                        "in": "query",
                        "schema": {
                            "type": "string",
                            "enum": [
                                "queued",
                                "claimed",
                                "submitted",
                                "sent",
                                "delivered",
                                "failed",
                                "received"
                            ]
                        }
                    },
                    {
                        "name": "page",
                        "in": "query",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Mesaj listesi"
                    }
                }
            },
            "post": {
                "operationId": "createOutboundMessage",
                "summary": "Standart REST API ile kuyruga yeni SMS ekler (Idempotency-Key basligi veya alani zorunludur).",
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "required": [
                                    "to",
                                    "body",
                                    "idempotency_key"
                                ],
                                "properties": {
                                    "to": {
                                        "type": "string"
                                    },
                                    "body": {
                                        "type": "string"
                                    },
                                    "idempotency_key": {
                                        "type": "string"
                                    }
                                }
                            }
                        }
                    }
                },
                "responses": {
                    "202": {
                        "description": "Mesaj kuyruga eklendi"
                    }
                }
            }
        },
        "/v1/ai/conversations": {
            "get": {
                "operationId": "listOrReadConversations",
                "summary": "Musteri SMS konusma dizilerini (gelen/giden gecmisini) listeler veya tek bir konusmanin mesajlarini getirir.",
                "parameters": [
                    {
                        "name": "status",
                        "in": "query",
                        "schema": {
                            "type": "string",
                            "enum": [
                                "unread",
                                "awaiting_reply",
                                "resolved"
                            ]
                        }
                    },
                    {
                        "name": "conversation_id",
                        "in": "query",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Konusma listesi veya detayi"
                    }
                }
            }
        },
        "/v1/ai/contacts": {
            "get": {
                "operationId": "listContacts",
                "summary": "Isletme rehberindeki kisileri arar ve listeler.",
                "parameters": [
                    {
                        "name": "q",
                        "in": "query",
                        "schema": {
                            "type": "string",
                            "description": "Isim veya telefon aramasi"
                        }
                    },
                    {
                        "name": "branch",
                        "in": "query",
                        "schema": {
                            "type": "string",
                            "description": "Sube filtresi"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Rehber kayitlari"
                    }
                }
            },
            "post": {
                "operationId": "upsertContact",
                "summary": "Rehbere yeni musteri ekler veya mevcut musteriyi gunceller.",
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "required": [
                                    "full_name",
                                    "phone"
                                ],
                                "properties": {
                                    "full_name": {
                                        "type": "string"
                                    },
                                    "phone": {
                                        "type": "string"
                                    },
                                    "branch": {
                                        "type": "string"
                                    },
                                    "tags": {
                                        "type": "string"
                                    },
                                    "marketing_consent": {
                                        "type": "string",
                                        "enum": [
                                            "unknown",
                                            "granted",
                                            "revoked"
                                        ]
                                    }
                                }
                            }
                        }
                    }
                },
                "responses": {
                    "200": {
                        "description": "Kisi eklendi veya guncellendi"
                    }
                }
            }
        },
        "/v1/ai/templates": {
            "get": {
                "operationId": "listTemplates",
                "summary": "Kayitli SMS sablonlarini listeler.",
                "responses": {
                    "200": {
                        "description": "Sablon listesi"
                    }
                }
            },
            "post": {
                "operationId": "createTemplate",
                "summary": "Yeni degiskenli ({{ad}}, {{sube}}, {{tarih}}) SMS sablonu olusturur.",
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "required": [
                                    "name",
                                    "body_template"
                                ],
                                "properties": {
                                    "name": {
                                        "type": "string"
                                    },
                                    "category": {
                                        "type": "string"
                                    },
                                    "body_template": {
                                        "type": "string"
                                    }
                                }
                            }
                        }
                    }
                },
                "responses": {
                    "201": {
                        "description": "Sablon olusturuldu"
                    }
                }
            }
        },
        "/v1/ai/campaigns": {
            "post": {
                "operationId": "createCampaign",
                "summary": "Rehber veya grup icin toplu SMS kampanyasi olusturur ve kuyruga alir.",
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "required": [
                                    "name",
                                    "body_template"
                                ],
                                "properties": {
                                    "name": {
                                        "type": "string"
                                    },
                                    "campaign_type": {
                                        "type": "string",
                                        "enum": [
                                            "service_notification",
                                            "marketing"
                                        ]
                                    },
                                    "group_id": {
                                        "type": "integer"
                                    },
                                    "body_template": {
                                        "type": "string"
                                    },
                                    "start_immediately": {
                                        "type": "boolean"
                                    }
                                }
                            }
                        }
                    }
                },
                "responses": {
                    "201": {
                        "description": "Kampanya olusturuldu"
                    }
                }
            }
        },
        "/v1/devices": {
            "get": {
                "operationId": "listDevices",
                "summary": "Isletmeye bagli Android telefonlari ve SIM durumlarini listeler.",
                "responses": {
                    "200": {
                        "description": "Cihaz listesi"
                    }
                }
            }
        }
    }
}