import json
import logging

from fastapi import APIRouter, HTTPException

from app.schemas.query_image import QueryImageModel
from app.schemas.response_template import ResponseModel
from app.service.search_image_with_text.service import query

router = APIRouter()
logger = logging.getLogger()


@router.post("/query_image")
def query_image(request_data: QueryImageModel):
    """
        对话机器人
        创建一个具有以下参数的请求体:
        - **gender**: 性别
        - **content**: 用户输入的内容

        示例参数：
        {
          "gender": "male",
          "content": "give me a long sleeve blouse",
        }
    """
    try:
        logger.info(f"query_image request item is : @@@@@@:{json.dumps(request_data.dict())}")
        data = query(request_data.gender, request_data.content)
        logger.info(f"query_image response @@@@@@:{json.dumps(data)}")
    except Exception as e:
        logger.warning(f"query_image Run Exception @@@@@@:{e}")
        raise HTTPException(status_code=404, detail=str(e))
    return ResponseModel(data=data)
