"""
数据库配置文件
"""
import os
from typing import Optional
# MySQL数据库配置

DATABASE_CONFIG = {
    "host": os.getenv("DB_HOST", "localhost"),
    "port": int(os.getenv("DB_PORT", 3306)),
    "user": os.getenv("DB_USER", "root"),
    "password": os.getenv("DB_PASSWORD", ""),
    "database": os.getenv("DB_NAME", "rollcall_system"),
    "charset": "utf8mb4"
}
if(mod:=os.getenv("DEV_MOD","DEV")):
    if(mod=="TEST"):
        DATABASE_CONFIG["database"] = "test_"+DATABASE_CONFIG["database"]

# FastAPI配置
API_HOST = "127.0.0.1"
API_PORT = 8000


# 数据库连接URL
def get_database_url() -> str:
    """生成数据库连接URL"""
    config = DATABASE_CONFIG
    return (f"mysql+pymysql://{config['user']}:{config['password']}"
            f"@{config['host']}:{config['port']}/{config['database']}"
            f"?charset={config['charset']}")
