{
  "openapi": "3.1.0",
  "info": {
    "title": "noithatcanho.vn — Ngân sách nội thất căn hộ (TA HOUSE)",
    "version": "1.0.0",
    "description": "API cho AI agent: tính ngân sách thi công nội thất căn hộ trọn gói theo đơn giá 2026 của TA HOUSE, và gửi yêu cầu bảng bóc tách chi tiết thay cho khách. Chỉ gửi lead khi khách đã đồng ý chia sẻ số điện thoại.",
    "contact": { "name": "TA HOUSE", "url": "https://tahouse.vn", "email": "web@tahouse.vn" }
  },
  "servers": [{ "url": "https://noithatcanho.vn" }],
  "paths": {
    "/api/estimate": {
      "get": {
        "operationId": "estimateInteriorBudget",
        "summary": "Tính ngân sách nội thất căn hộ",
        "parameters": [
          { "name": "pn", "in": "query", "required": true, "description": "Số phòng ngủ: 1, 2, 3, hoặc 4 cho duplex/penthouse.", "schema": { "type": "string", "enum": ["1", "2", "3", "4"] } },
          { "name": "m2", "in": "query", "required": false, "description": "Diện tích sử dụng (m²), 30–300. Bỏ trống thì dùng diện tích thường gặp theo số phòng ngủ.", "schema": { "type": "integer", "minimum": 30, "maximum": 300 } },
          { "name": "pc", "in": "query", "required": false, "description": "Phong cách. Mặc định toi-gian.", "schema": { "type": "string", "enum": ["toi-gian", "japandi"], "default": "toi-gian" } }
        ],
        "responses": {
          "200": { "description": "Ngân sách tham khảo", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Estimate" } } } },
          "400": { "description": "Tham số sai", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
        }
      }
    },
    "/api/lead": {
      "post": {
        "operationId": "requestDetailedQuote",
        "summary": "Gửi yêu cầu bảng bóc tách chi tiết cho kiến trúc sư TA HOUSE",
        "description": "Kiến trúc sư TA HOUSE liên hệ khách qua Zalo theo số điện thoại. Bắt buộc consent=true.",
        "requestBody": {
          "required": true,
          "content": { "application/json": { "schema": {
            "type": "object",
            "required": ["phone", "pn", "consent"],
            "properties": {
              "phone": { "type": "string", "description": "Số điện thoại Việt Nam của khách, 10 số." },
              "pn": { "type": "string", "enum": ["1", "2", "3", "4"] },
              "m2": { "type": "integer", "minimum": 30, "maximum": 300 },
              "pc": { "type": "string", "enum": ["toi-gian", "japandi"] },
              "name": { "type": "string", "maxLength": 80 },
              "note": { "type": "string", "maxLength": 500, "description": "Tên dự án chung cư, thời điểm nhận nhà, mong muốn riêng." },
              "agent": { "type": "string", "maxLength": 80, "description": "Tên AI agent gửi yêu cầu." },
              "consent": { "type": "boolean", "const": true, "description": "Khách đồng ý để TA HOUSE dùng số điện thoại này gửi bảng bóc tách." }
            }
          } } }
        },
        "responses": {
          "201": { "description": "Đã nhận", "content": { "application/json": { "schema": { "type": "object", "properties": { "ok": { "type": "boolean" }, "quote_id": { "type": "string" }, "message": { "type": "string" }, "zalo": { "type": "string" }, "estimate": { "$ref": "#/components/schemas/Estimate" } } } } } },
          "422": { "description": "Thiếu hoặc sai dữ liệu", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "429": { "description": "Quá nhiều yêu cầu", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Error": { "type": "object", "properties": { "ok": { "type": "boolean" }, "error": { "type": "string" } } },
      "Estimate": {
        "type": "object",
        "properties": {
          "quote_id": { "type": "string", "description": "Mã báo giá, đọc cho kiến trúc sư khi nhắn Zalo." },
          "input": { "type": "object" },
          "build_budget_vnd": { "type": "object", "properties": { "min": { "type": "integer" }, "max": { "type": "integer" } } },
          "build_budget_text": { "type": "string" },
          "design_fee_vnd": { "type": "integer" },
          "design_fee_when_building_vnd": { "type": "integer" },
          "timeline_weeks": { "type": "object" },
          "excludes": { "type": "array", "items": { "type": "string" } },
          "notes": { "type": "array", "items": { "type": "string" } },
          "is_official_quote": { "type": "boolean" },
          "share_url": { "type": "string" },
          "next_step": { "type": "object" },
          "provider": { "type": "object" }
        }
      }
    }
  }
}
