{
  "openapi": "3.0.3",
  "info": {
    "title": "RBM Mühendislik Fiyat ve Teklif API",
    "description": "Yapay zekâ asistanları ve otomasyon istemcileri için hizmet kataloğu, kişisel veri gerektirmeyen yaklaşık fiyat hesabı ve insan onaylı teklif taslağı API'si. Yaklaşık hesap resmî teklif değildir.",
    "version": "2.0.0",
    "contact": {
      "name": "RBM Mühendislik",
      "email": "info@rbmmuhendislik.com",
      "url": "https://www.rbmmuhendislik.com/teklif-al.html"
    }
  },
  "servers": [
    {
      "url": "https://www.rbmmuhendislik.com",
      "description": "Canlı sunucu"
    }
  ],
  "paths": {
    "/api/v1/catalog.php": {
      "get": {
        "operationId": "getServiceCatalog",
        "summary": "Hizmetleri, gerekli ölçüleri ve güncel fiyat kurallarını getir",
        "description": "Fiyat sormadan önce bu uç kullanılarak geçerli service_id değerleri ve kullanıcıdan istenmesi gereken ölçüler öğrenilir.",
        "responses": {
          "200": {
            "description": "Güncel hizmet kataloğu",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CatalogResponse"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/api/v1/estimates.php": {
      "post": {
        "operationId": "calculateEstimate",
        "summary": "KDV hariç ve KDV dâhil yaklaşık fiyat hesapla",
        "description": "Kişisel bilgi istemeden hizmet, adet, m² ve kat bilgilerine göre yaklaşık fiyat hesaplar. Eksik giriş varsa needs_input yanıtıyla sorulması gereken bilgileri döndürür.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EstimateRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Yaklaşık fiyat hesaplandı",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EstimateResponse"
                }
              }
            }
          },
          "422": {
            "description": "Eksik giriş, geçersiz hizmet veya mühendis incelemesi gerekiyor"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      },
      "get": {
        "summary": "Fiyat Tahmini Hesapla (GET Query-String)",
        "description": "Sadece GET yapabilen yapay zeka asistanları ve istemciler için query-string üzerinden fiyat hesaplar. POST yöntemiyle tamamen aynı JSON yanıtını döner.",
        "operationId": "calculateEstimateGet",
        "parameters": [
          {
            "name": "service_ids",
            "in": "query",
            "required": false,
            "description": "Virgülle ayrılmış geçerli hizmet ID'leri (örn: topraklama-muayenesi,elektrik-ic-tesisat-muayenesi).",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "quantities",
            "in": "query",
            "required": false,
            "description": "Virgülle ayrılmış pozitif adetler (örn: 3,3). service_ids ile birebir eşleşmeli.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "m2",
            "in": "query",
            "required": false,
            "description": "İşletmenin yaklaşık kapalı alanı (m²).",
            "schema": {
              "type": "integer",
              "minimum": 1
            }
          },
          {
            "name": "kat",
            "in": "query",
            "required": false,
            "description": "İşletmenin kat sayısı.",
            "schema": {
              "type": "integer",
              "minimum": 1
            }
          },
          {
            "name": "city",
            "in": "query",
            "required": false,
            "description": "Hizmetin sunulacağı il.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "district",
            "in": "query",
            "required": false,
            "description": "Hizmetin sunulacağı ilçe.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Yaklaşık fiyat hesaplandı",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EstimateResponse"
                }
              }
            }
          },
          "422": {
            "description": "Eksik giriş, geçersiz hizmet veya mühendis incelemesi gerekiyor"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/api/v1/quote-drafts.php": {
      "post": {
        "operationId": "createQuoteDraft",
        "summary": "Kullanıcı onayına sunulacak teklif talebi taslağı oluştur",
        "description": "Bu işlem e-posta göndermez ve kalıcı müşteri talebi oluşturmaz. İnsan tarafından açılması gereken süreli confirmation_url döndürür. Aynı işlemin tekrarını önlemek için Idempotency-Key kullanılmalıdır.",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "description": "Aynı mantıksal teklif taslağı için tekrar kullanılan benzersiz istemci anahtarı",
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 200
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/QuoteDraftRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Taslak oluşturuldu; insan onayı bekleniyor",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/QuoteDraftResponse"
                }
              }
            }
          },
          "422": {
            "description": "Eksik veya geçersiz iletişim/fiyat bilgisi"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/api/calculate_quote.php": {
      "get": {
        "operationId": "getLegacyPricingCatalog",
        "summary": "Salt-Okunur Fiyat ve Katalog API (GET Query-String)",
        "description": "Mevcut entegrasyonların çalışmaya devam etmesi için korunur. Yeni entegrasyonlar /api/v1/catalog.php ve /api/v1/estimates.php kullanmalıdır.",
        "responses": {
          "200": {
            "description": "Katalog veya fiyat sonucu"
          }
        },
        "parameters": [
          {
            "name": "service_ids",
            "in": "query",
            "required": false,
            "description": "Virgülle ayrılmış geçerli hizmet ID'leri (örn: topraklama-muayenesi,elektrik-ic-tesisat-muayenesi).",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "quantities",
            "in": "query",
            "required": false,
            "description": "Virgülle ayrılmış pozitif adetler (örn: 3,3). service_ids ile birebir eşleşmeli.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "m2",
            "in": "query",
            "required": false,
            "description": "İşletmenin yaklaşık kapalı alanı (m²).",
            "schema": {
              "type": "integer",
              "minimum": 1
            }
          },
          {
            "name": "kat",
            "in": "query",
            "required": false,
            "description": "İşletmenin kat sayısı.",
            "schema": {
              "type": "integer",
              "minimum": 1
            }
          },
          {
            "name": "city",
            "in": "query",
            "required": false,
            "description": "Hizmetin sunulacağı il.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "district",
            "in": "query",
            "required": false,
            "description": "Hizmetin sunulacağı ilçe.",
            "schema": {
              "type": "string"
            }
          }
        ]
      },
      "post": {
        "operationId": "calculateLegacyEstimate",
        "summary": "Geriye uyumlu yaklaşık fiyat hesabı",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/LegacyEstimateRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Yaklaşık fiyat sonucu"
          }
        }
      }
    }
  },
  "components": {
    "responses": {
      "RateLimited": {
        "description": "İstek sınırı aşıldı"
      }
    },
    "schemas": {
      "ServiceSelection": {
        "type": "object",
        "required": [
          "service_id"
        ],
        "properties": {
          "service_id": {
            "type": "string",
            "example": "topraklama-muayenesi"
          },
          "quantity": {
            "type": "integer",
            "minimum": 1,
            "example": 20
          }
        }
      },
      "Facility": {
        "type": "object",
        "required": [
          "square_meters",
          "floor_count"
        ],
        "properties": {
          "square_meters": {
            "type": "integer",
            "minimum": 1,
            "example": 1000
          },
          "floor_count": {
            "type": "integer",
            "minimum": 1,
            "example": 2
          },
          "city": {
            "type": "string",
            "example": "İstanbul"
          },
          "district": {
            "type": "string",
            "example": "Bağcılar"
          }
        }
      },
      "EstimateRequest": {
        "type": "object",
        "required": [
          "services",
          "facility"
        ],
        "properties": {
          "services": {
            "type": "array",
            "minItems": 1,
            "items": {
              "$ref": "#/components/schemas/ServiceSelection"
            }
          },
          "facility": {
            "$ref": "#/components/schemas/Facility"
          }
        },
        "example": {
          "services": [
            {
              "service_id": "acil-tahliye-plani-cizimi",
              "quantity": 1
            }
          ],
          "facility": {
            "square_meters": 500,
            "floor_count": 2,
            "city": "İstanbul",
            "district": "Bağcılar"
          }
        }
      },
      "CatalogResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean"
          },
          "tariff_version": {
            "type": "string"
          },
          "service_count": {
            "type": "integer"
          },
          "services": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "service_id": {
                  "type": "string"
                },
                "name_tr": {
                  "type": "string"
                },
                "base_price_ex_vat": {
                  "type": "number"
                },
                "unit_price_ex_vat": {
                  "type": "number"
                },
                "required_inputs": {
                  "type": "array",
                  "items": {
                    "type": "object"
                  }
                },
                "pricing_summary_tr": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "EstimateResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "example": true
          },
          "status": {
            "type": "string",
            "example": "calculated"
          },
          "calculation_id": {
            "type": "string"
          },
          "is_estimate": {
            "type": "boolean",
            "example": true
          },
          "currency": {
            "type": "string",
            "example": "TRY"
          },
          "net_total_ex_vat": {
            "type": "number",
            "example": 10000
          },
          "vat_rate": {
            "type": "number",
            "example": 0.2
          },
          "vat_total": {
            "type": "number",
            "example": 2000
          },
          "gross_total_inc_vat": {
            "type": "number",
            "example": 12000
          },
          "tariff_version": {
            "type": "string"
          },
          "source_url": {
            "type": "string",
            "format": "uri"
          }
        }
      },
      "Contact": {
        "type": "object",
        "required": [
          "company_name",
          "contact_name",
          "phone",
          "email"
        ],
        "properties": {
          "company_name": {
            "type": "string"
          },
          "contact_name": {
            "type": "string"
          },
          "phone": {
            "type": "string"
          },
          "email": {
            "type": "string",
            "format": "email"
          },
          "address": {
            "type": "string"
          }
        }
      },
      "QuoteDraftRequest": {
        "type": "object",
        "required": [
          "contact",
          "estimate"
        ],
        "properties": {
          "contact": {
            "$ref": "#/components/schemas/Contact"
          },
          "estimate": {
            "$ref": "#/components/schemas/EstimateRequest"
          },
          "notes": {
            "type": "string",
            "maxLength": 3000
          }
        }
      },
      "QuoteDraftResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "example": true
          },
          "status": {
            "type": "string",
            "example": "draft_pending_confirmation"
          },
          "draft_id": {
            "type": "string"
          },
          "is_email_sent": {
            "type": "boolean",
            "example": false
          },
          "is_quote_submitted": {
            "type": "boolean",
            "example": false
          },
          "requires_human_confirmation": {
            "type": "boolean",
            "example": true
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          },
          "confirmation_url": {
            "type": "string",
            "format": "uri"
          }
        }
      },
      "LegacyEstimateRequest": {
        "type": "object",
        "properties": {
          "m2": {
            "type": "integer"
          },
          "kat_sayisi": {
            "type": "integer"
          },
          "hizmetler": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "adetler": {
            "type": "object",
            "additionalProperties": {
              "type": "integer"
            }
          }
        }
      }
    }
  }
}