{
 "openapi": "3.1.0",
 "info": {
  "title": "Hoa lụa Vân Vượng — API mua hàng cho AI agent",
  "version": "1.0.0",
  "description": "Tra giá, tình trạng còn hàng và đặt hàng giao tận nhà (dat_ngay=true khi người dùng đã đồng ý trong chat; mặc định tạo đơn CHỜ XÁC NHẬN) tại Tổng kho Hoa lụa Vân Vượng (2A Hàng Rươi, Hoàn Kiếm, Hà Nội). Đơn chỉ được đặt khi người mua tự mở link_xac_nhan và bấm xác nhận. Giá tính phía máy chủ (giá lẻ, VND, đã gồm VAT). Không cần đăng nhập. Máy chủ MCP tương đương: https://hoaluavanvuong.com/mcp",
  "contact": {
   "name": "Hoa lụa Vân Vượng — Zalo/hotline 0963 399 066",
   "url": "https://hoaluavanvuong.com"
  }
 },
 "servers": [
  {
   "url": "https://hoaluavanvuong.com"
  }
 ],
 "paths": {
  "/api/agent/san-pham": {
   "get": {
    "operationId": "timSanPham",
    "summary": "Tìm sản phẩm hoặc xem một mã",
    "parameters": [
     {
      "name": "q",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Từ khoá tiếng Việt, có hoặc không dấu (vd. hồ điệp trắng, cây bàng)."
     },
     {
      "name": "ma",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Một mã sản phẩm (SP...). Có tham số này thì bỏ qua q."
     },
     {
      "name": "danh_muc",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Lọc danh mục, vd. Cây, Hoa cành dài, Hồ điệp, lan, Sen, Lọ hoa."
     },
     {
      "name": "gia_toi_da",
      "in": "query",
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "gioi_han",
      "in": "query",
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 50,
       "default": 10
      }
     },
     {
      "name": "ca_het_hang",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "1"
       ]
      },
      "description": "Truyền 1 để gồm cả mã đang hết hàng."
     }
    ],
    "responses": {
     "200": {
      "description": "Danh sách sản phẩm",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "so_ket_qua": {
           "type": "integer"
          },
          "san_pham": {
           "description": "Mảng sản phẩm khi tìm bằng q; một đối tượng SanPham khi tra bằng ma.",
           "oneOf": [
            {
             "type": "array",
             "items": {
              "$ref": "#/components/schemas/SanPham"
             }
            },
            {
             "$ref": "#/components/schemas/SanPham"
            }
           ]
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "Không có mã"
     }
    }
   }
  },
  "/api/agent/don-hang": {
   "post": {
    "operationId": "taoDonChoXacNhan",
    "summary": "Đặt hàng giao tận nhà (dat_ngay=true) hoặc tạo đơn chờ xác nhận",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/YeuCauDon"
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Đã tạo đơn chờ xác nhận. Gửi link_xac_nhan cho người dùng.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Don"
        }
       }
      }
     },
     "400": {
      "description": "Dữ liệu sai (mã không có, số điện thoại sai, thiếu địa chỉ)"
     },
     "429": {
      "description": "Quá nhiều đơn từ cùng số điện thoại trong 1 giờ (tối đa 5)"
     }
    }
   },
   "get": {
    "operationId": "xemDon",
    "summary": "Xem trạng thái đơn theo mã xác nhận",
    "parameters": [
     {
      "name": "ma",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string",
       "pattern": "^[0-9a-f]{32}$"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Đơn",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Don"
        }
       }
      }
     },
     "404": {
      "description": "Không có hoặc đã hết hạn 48 giờ"
     }
    }
   }
  }
 },
 "components": {
  "schemas": {
   "SanPham": {
    "type": "object",
    "properties": {
     "ma": {
      "type": "string"
     },
     "ten": {
      "type": "string"
     },
     "ten_mau": {
      "type": "string"
     },
     "phan_loai": {
      "type": "string"
     },
     "danh_muc": {
      "type": "string"
     },
     "gia_le": {
      "type": "integer",
      "description": "VND, đã gồm VAT"
     },
     "con_hang": {
      "type": "boolean"
     },
     "anh": {
      "type": "string",
      "format": "uri"
     },
     "link": {
      "type": "string",
      "format": "uri"
     }
    }
   },
   "YeuCauDon": {
    "type": "object",
    "required": [
     "san_pham",
     "khach_hang"
    ],
    "properties": {
     "san_pham": {
      "type": "array",
      "minItems": 1,
      "maxItems": 50,
      "items": {
       "type": "object",
       "required": [
        "ma",
        "so_luong"
       ],
       "properties": {
        "ma": {
         "type": "string"
        },
        "so_luong": {
         "type": "integer",
         "minimum": 1,
         "maximum": 999
        }
       }
      }
     },
     "khach_hang": {
      "type": "object",
      "required": [
       "ten",
       "dien_thoai",
       "dia_chi"
      ],
      "properties": {
       "ten": {
        "type": "string"
       },
       "dien_thoai": {
        "type": "string",
        "description": "Số Việt Nam 10 số (0xxxxxxxxx hoặc +84...)"
       },
       "dia_chi": {
        "type": "string"
       }
      }
     },
     "thanh_toan": {
      "type": "string",
      "enum": [
       "cod",
       "transfer"
      ],
      "default": "cod"
     },
     "ghi_chu": {
      "type": "string"
     },
     "nguon": {
      "type": "string",
      "description": "Tên agent/ứng dụng gửi đơn"
     },
     "dat_ngay": {
      "type": "boolean",
      "default": false,
      "description": "true = người dùng đã đồng ý trong chat → đặt luôn, trả ma_don_kiotviet. false = tạo đơn chờ + link_xac_nhan."
     }
    }
   },
   "Don": {
    "type": "object",
    "properties": {
     "ma_xac_nhan": {
      "type": "string"
     },
     "trang_thai": {
      "type": "string",
      "enum": [
       "cho_xac_nhan",
       "da_xac_nhan"
      ]
     },
     "link_xac_nhan": {
      "type": "string",
      "format": "uri"
     },
     "het_han_sau_gio": {
      "type": "integer"
     },
     "tam_tinh": {
      "type": "integer"
     },
     "phi_giao_hang": {
      "type": "string"
     },
     "thanh_toan": {
      "type": "string"
     },
     "ma_don_kiotviet": {
      "type": [
       "string",
       "null"
      ]
     },
     "san_pham": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "ma": {
         "type": "string"
        },
        "ten": {
         "type": "string"
        },
        "so_luong": {
         "type": "integer"
        },
        "don_gia": {
         "type": "integer"
        },
        "thanh_tien": {
         "type": "integer"
        },
        "con_hang": {
         "type": "boolean"
        }
       }
      }
     }
    }
   }
  }
 }
}