import json
import logging

from fastapi import APIRouter, HTTPException

from app.schemas.chat_robot import ChatRobotModel
from app.schemas.response_template import ResponseModel
from app.service.chat_robot.script.main import chat

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


@router.post("/chat_robot")
def chat_robot(request_data: ChatRobotModel):
    """
        对话机器人
        创建一个具有以下参数的请求体:
        - **gender**: 服装类别
        - **message**: 消息
        - **session_id**: 会话id
        - **user_id**: 用户id

        示例参数：
        {
          "gender": "male",
          "message": "你好",
          "session_id": "string-89",
          "user_id": 89
        }
    """
    try:
        logger.info(f"chat_robot request item is : @@@@@@:{json.dumps(request_data.dict())}")
        data = chat(post_data=request_data)
        logger.info(f"chat_robot response @@@@@@:{json.dumps(data)}")
    except Exception as e:
        logger.warning(f"chat_robot Run Exception @@@@@@:{e}")
        raise HTTPException(status_code=404, detail=str(e))
    return ResponseModel(data=data)
