{
  "openapi": "3.1.0",
  "info": {
    "title": "İçtihat Pro Emsal Karar API",
    "version": "1.0.0",
    "description": "Türkiye'deki Yargıtay, Danıştay, bölge adliye (istinaf), yerel mahkeme ve kanun yararına bozma kararlarını künye, tam metin ve kanun atıflarıyla döndüren REST API. Tüm cevaplar {\"success\":true,\"data\":…,\"meta\":…} zarfıyla, hatalar {\"success\":false,\"error\":{\"code\",\"message\"}} zarfıyla döner. Belgeler: https://ictihatpro.com/api-docs",
    "termsOfService": "https://ictihatpro.com/kullanim-sartlari",
    "contact": { "name": "İçtihat Pro", "url": "https://ictihatpro.com/iletisim", "email": "destek@ictihatpro.com" }
  },
  "externalDocs": { "description": "Geliştirici belgeleri ve canlı deneme konsolu", "url": "https://ictihatpro.com/api-docs" },
  "servers": [ { "url": "https://ictihatpro.com/api/v1" } ],
  "security": [ { "bearerAuth": [] } ],
  "tags": [
    { "name": "Kararlar", "description": "Emsal karar arama ve karar metni" },
    { "name": "Mevzuat", "description": "Kanun ve kanun maddesi" },
    { "name": "Hesap", "description": "Kota durumu" }
  ],
  "paths": {
    "/search": {
      "get": {
        "tags": ["Kararlar"], "operationId": "searchDecisions", "summary": "Karar arama",
        "description": "Kelime, tam ifade, esas/karar numarası veya doğal dil sorgusuyla kararları arar.",
        "parameters": [
          { "name": "q", "in": "query", "required": true, "description": "Arama sorgusu, en az 2 karakter.", "schema": { "type": "string", "minLength": 2 }, "example": "işe iade" },
          { "name": "mode", "in": "query", "description": "lexical (varsayılan) veya hybrid (kelime + anlamsal).", "schema": { "type": "string", "enum": ["lexical", "hybrid"], "default": "lexical" } },
          { "name": "rerank", "in": "query", "description": "Yalnız mode=hybrid ile: sonuçları yapay zekâ modeliyle yeniden sıralar.", "schema": { "type": "integer", "enum": [0, 1] } },
          { "name": "parse", "in": "query", "description": "Tırnaklı ifade, E./K. numarası, daire ve mahkeme sözdizimini çözümler.", "schema": { "type": "integer", "enum": [0, 1] } },
          { "name": "aggs", "in": "query", "description": "data.aggs altında filtre sayılarını döndürür.", "schema": { "type": "integer", "enum": [0, 1] } },
          { "name": "mahkeme", "in": "query", "description": "Virgülle çoklu: yargitay, danistay, istinaf, yerel-hukuk, kyb.", "schema": { "type": "string" }, "example": "yargitay" },
          { "name": "daire", "in": "query", "description": "Örn. 9. Hukuk Dairesi; virgülle çoklu.", "schema": { "type": "string" } },
          { "name": "dava_turu", "in": "query", "schema": { "type": "string", "enum": ["HUKUK", "CEZA", "IDARI", "VERGI", "DIGER"] } },
          { "name": "karar_sonucu", "in": "query", "description": "Virgülle çoklu.", "schema": { "type": "string" } },
          { "name": "hukuk_alani", "in": "query", "description": "Virgülle çoklu.", "schema": { "type": "string" } },
          { "name": "ust_mahkeme", "in": "query", "description": "Virgülle çoklu.", "schema": { "type": "string" } },
          { "name": "oy_durumu", "in": "query", "description": "Virgülle çoklu.", "schema": { "type": "string" } },
          { "name": "esas_no", "in": "query", "schema": { "type": "string" }, "example": "2023/1234" },
          { "name": "karar_no", "in": "query", "schema": { "type": "string" } },
          { "name": "tarih_baslangic", "in": "query", "schema": { "type": "string", "format": "date" } },
          { "name": "tarih_bitis", "in": "query", "schema": { "type": "string", "format": "date" } },
          { "name": "sort", "in": "query", "schema": { "type": "string", "enum": ["relevance", "newest", "oldest"], "default": "relevance" } },
          { "name": "page", "in": "query", "schema": { "type": "integer", "minimum": 1, "maximum": 500, "default": 1 } },
          { "name": "per_page", "in": "query", "schema": { "type": "integer", "minimum": 1, "maximum": 50, "default": 20 } }
        ],
        "responses": {
          "200": { "description": "Arama sonuçları", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/SearchResponse" } } } },
          "401": { "$ref": "#/components/responses/Error" }, "403": { "$ref": "#/components/responses/Error" },
          "422": { "$ref": "#/components/responses/Error" }, "429": { "$ref": "#/components/responses/RateLimited" }, "500": { "$ref": "#/components/responses/Error" }
        }
      }
    },
    "/karar/{id}": {
      "get": {
        "tags": ["Kararlar"], "operationId": "getDecision", "summary": "Karar detayı",
        "description": "Kararın tam metnini (düz metin ve temizlenmiş HTML) ve künyesini döndürür.",
        "parameters": [ { "$ref": "#/components/parameters/DecisionId" } ],
        "responses": {
          "200": { "description": "Karar", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/DecisionResponse" } } } },
          "401": { "$ref": "#/components/responses/Error" }, "404": { "$ref": "#/components/responses/Error" },
          "422": { "$ref": "#/components/responses/Error" }, "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/karar/{id}/benzer": {
      "get": {
        "tags": ["Kararlar"], "operationId": "getSimilarDecisions", "summary": "Benzer kararlar",
        "description": "Verilen karara içerik olarak en çok benzeyen 5 kararı döndürür.",
        "parameters": [ { "$ref": "#/components/parameters/DecisionId" } ],
        "responses": {
          "200": { "description": "Benzer kararlar", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/SearchResponse" } } } },
          "401": { "$ref": "#/components/responses/Error" }, "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/kanunlar": {
      "get": {
        "tags": ["Mevzuat"], "operationId": "searchLaws", "summary": "Kanun arama",
        "parameters": [
          { "name": "q", "in": "query", "description": "Kanun adı, numarası veya içerik.", "schema": { "type": "string" }, "example": "borçlar kanunu" },
          { "name": "page", "in": "query", "schema": { "type": "integer", "minimum": 1, "default": 1 } },
          { "name": "per_page", "in": "query", "schema": { "type": "integer", "minimum": 1, "maximum": 50, "default": 20 } }
        ],
        "responses": {
          "200": { "description": "Kanunlar", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Envelope" } } } },
          "401": { "$ref": "#/components/responses/Error" }, "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/kanun/madde": {
      "get": {
        "tags": ["Mevzuat"], "operationId": "getLawArticle", "summary": "Kanun maddesi",
        "description": "Resmî kanun metninden tek maddeyi döndürür. no veya id zorunludur.",
        "parameters": [
          { "name": "no", "in": "query", "description": "Kanun numarası.", "schema": { "type": "string" }, "example": "6098" },
          { "name": "id", "in": "query", "description": "Kanun kimliği (/kanunlar sonucundaki id).", "schema": { "type": "integer" } },
          { "name": "madde", "in": "query", "required": true, "description": "350, ek-1 veya gecici-1 biçiminde.", "schema": { "type": "string" }, "example": "350" }
        ],
        "responses": {
          "200": { "description": "Madde", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ArticleResponse" } } } },
          "400": { "$ref": "#/components/responses/Error" }, "404": { "$ref": "#/components/responses/Error" },
          "422": { "$ref": "#/components/responses/Error" }, "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/kanun/maddeler": {
      "get": {
        "tags": ["Mevzuat"], "operationId": "searchLawArticles", "summary": "Konuya göre madde arama",
        "parameters": [
          { "name": "q", "in": "query", "required": true, "schema": { "type": "string", "minLength": 3 }, "example": "kira bedelinin tespiti" },
          { "name": "no", "in": "query", "description": "Aramayı tek kanunla sınırlar.", "schema": { "type": "string" } },
          { "name": "limit", "in": "query", "schema": { "type": "integer", "minimum": 1, "maximum": 20, "default": 5 } },
          { "name": "min_match", "in": "query", "description": "Yalnız no ile: 0.1–1.0.", "schema": { "type": "number", "minimum": 0.1, "maximum": 1, "default": 0.5 } }
        ],
        "responses": {
          "200": { "description": "Maddeler", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Envelope" } } } },
          "400": { "$ref": "#/components/responses/Error" }, "404": { "$ref": "#/components/responses/Error" },
          "422": { "$ref": "#/components/responses/Error" }, "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/usage": {
      "get": {
        "tags": ["Hesap"], "operationId": "getUsage", "summary": "Kota durumu",
        "description": "Günlük kullanımı ve limitleri döndürür; kotadan düşmez.",
        "responses": {
          "200": { "description": "Kullanım", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/UsageResponse" } } } },
          "401": { "$ref": "#/components/responses/Error" }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": { "type": "http", "scheme": "bearer", "description": "Authorization: Bearer ipk_live_… (alternatif: X-Api-Key başlığı)" }
    },
    "parameters": {
      "DecisionId": { "name": "id", "in": "path", "required": true, "description": "Arama sonucundaki id.", "schema": { "type": "string", "pattern": "^[0-9]+$" }, "example": "325399600" }
    },
    "responses": {
      "Error": { "description": "Hata", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
      "RateLimited": {
        "description": "İstek aralığı veya günlük kota aşıldı (rate_limited, quota_exceeded).",
        "headers": { "Retry-After": { "description": "Beklenecek saniye", "schema": { "type": "integer" } } },
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
      }
    },
    "schemas": {
      "Envelope": {
        "type": "object",
        "properties": { "success": { "type": "boolean" }, "data": { "type": "object" }, "meta": { "type": "object" } }
      },
      "Error": {
        "type": "object",
        "properties": {
          "success": { "type": "boolean", "const": false },
          "error": { "type": "object", "properties": { "code": { "type": "string" }, "message": { "type": "string" } } }
        }
      },
      "DecisionSummary": {
        "type": "object",
        "properties": {
          "id": { "type": "string" }, "mahkeme": { "type": ["string", "null"] }, "daire": { "type": ["string", "null"] },
          "esas_no": { "type": ["string", "null"] }, "karar_no": { "type": ["string", "null"] },
          "karar_tarihi": { "type": ["string", "null"], "format": "date" }, "ozet": { "type": ["string", "null"] },
          "ozet_html": { "type": ["string", "null"], "description": "Yalnız <mark> içerir; geri kalanı escape edilmiştir." },
          "url": { "type": "string", "format": "uri" }, "mahkeme_turu": { "type": ["string", "null"] },
          "dava_turu": { "type": ["string", "null"] }, "karar_sonucu": { "type": ["string", "null"] },
          "hukuk_alani": { "type": ["string", "null"] }, "oy_durumu": { "type": ["string", "null"] }, "konu_basligi": { "type": ["string", "null"] }
        }
      },
      "SearchResponse": {
        "type": "object",
        "properties": {
          "success": { "type": "boolean" },
          "data": { "type": "object", "properties": { "results": { "type": "array", "items": { "$ref": "#/components/schemas/DecisionSummary" } }, "aggs": { "type": "object" } } },
          "meta": { "type": "object" }
        }
      },
      "DecisionResponse": {
        "type": "object",
        "properties": {
          "success": { "type": "boolean" },
          "data": { "type": "object", "properties": { "karar": {
            "allOf": [ { "$ref": "#/components/schemas/DecisionSummary" } ],
            "properties": {
              "metin": { "type": "string" }, "metin_html": { "type": ["string", "null"] },
              "kanun_referanslari": { "type": "array", "items": { "type": "object", "properties": { "kanun_no": { "type": "string" }, "kanun_adi": { "type": "string" } } } }
            }
          } } }
        }
      },
      "ArticleResponse": {
        "type": "object",
        "properties": {
          "success": { "type": "boolean" },
          "data": { "type": "object", "properties": {
            "kanun": { "type": "object", "properties": { "id": { "type": "integer" }, "mevzuat_no": { "type": "string" }, "baslik": { "type": "string" }, "kabul_tarihi": { "type": ["string", "null"] }, "rg_tarihi": { "type": ["string", "null"] }, "kategori": { "type": "string" } } },
            "madde": { "type": "object", "properties": { "key": { "type": "string" }, "no": { "type": "string" }, "tur": { "type": "string" }, "baslik": { "type": ["string", "null"] }, "metin": { "type": "string" }, "degisiklik_notlari": { "type": "array", "items": { "type": "string" } }, "mulga": { "type": "boolean" }, "onceki": { "type": ["string", "null"] }, "sonraki": { "type": ["string", "null"] } } }
          } },
          "meta": { "type": "object", "properties": { "madde_sayisi": { "type": "integer" } } }
        }
      },
      "UsageResponse": {
        "type": "object",
        "properties": {
          "success": { "type": "boolean" },
          "data": { "type": "object", "properties": { "usage": { "type": "object", "properties": {
            "plan": { "type": "string" }, "daily_limit": { "type": ["integer", "null"] }, "daily_used": { "type": "integer" },
            "daily_remaining": { "type": ["integer", "null"] }, "per_minute_limit": { "type": ["integer", "null"] },
            "min_interval_sec": { "type": ["integer", "null"] }, "resets_at": { "type": "string", "format": "date-time" }
          } } } }
        }
      }
    }
  }
}
