import time
from math import log
import os
from dotenv import load_dotenv
from foundation.core_enums import ErrorCodeEnum
from functools import wraps

from foundation.logger.loggering import server_logger
from foundation.utils.common import handler_err
from foundation.base.config import config_handler
import json
from datetime import datetime, date
# 获取当前文件的目录
current_dir = os.path.dirname(__file__)
# 构建到 .env 的相对路径
conf_file_path = os.path.join(current_dir , '../',  '.env')
#server_logger.info(f"当前目录: {conf_file_path}")
# 加载环境变量
load_dotenv(dotenv_path=conf_file_path)

def verify_param(param: dict):
    """
        验证请求参数
    """
    input_data = param.get("input")
    session_id = param.get("config").get("session_id")
    if input_data is None:
        raise ValueError(ErrorCodeEnum.INPUT_INFO_EMPTY.__str__)
    if session_id is None:
        raise ValueError(ErrorCodeEnum.SESSION_ID_EMPTY.__str__)
    



def get_system_prompt() -> str:
    """
        获取系统提示语
    """
    system_prompt = config_handler.get("system", "SYSTEM_PROMPT")
    server_logger.info(f"获取系统提示语: {system_prompt}")
    return str(system_prompt)






class DateTimeEncoder(json.JSONEncoder):
    def default(self, obj):
        if isinstance(obj, datetime):
            return obj.strftime('%Y-%m-%d %H:%M:%S')
        elif isinstance(obj, date):  # 添加对 date 类型的支持
            return obj.strftime('%Y-%m-%d')
        return super().default(obj)