#!/usr/bin/env python
"""
创建一个测试端点来调试
"""

import asyncio
import sys
from pathlib import Path

# 添加项目根目录到 Python 路径
project_root = Path(__file__).parent
sys.path.append(str(project_root))

import uvicorn
from fastapi import FastAPI
from app.api.v1 import api_router

# 创建应用
app = FastAPI(title="调试API")

# 包含现有路由
app.include_router(api_router, prefix="/api/v1")

# 添加测试路由
from fastapi import Depends
from app.core.deps import get_current_user
from app.schemas.user import User as UserSchema
from app.schemas.base import ResponseModel

@app.get("/debug/user/raw")
async def debug_user_raw(current_user = Depends(get_current_user)):
    """直接返回用户对象的dict"""
    return {
        "id": current_user.id,
        "username": current_user.username,
        "email": current_user.email,
        "phone": current_user.phone,
        "school": current_user.school,
        "major": current_user.major,
        "full_name": current_user.full_name,
        "bio": current_user.bio,
        "gender": current_user.gender,
        "role": current_user.role
    }

@app.get("/debug/user/schema")
async def debug_user_schema(current_user = Depends(get_current_user)):
    """使用UserSchema序列化"""
    return UserSchema.model_validate(current_user)

@app.get("/debug/user/response")
async def debug_user_response(current_user = Depends(get_current_user)):
    """使用ResponseModel包装"""
    return ResponseModel(data=UserSchema.model_validate(current_user))

@app.get("/debug/user/dict")
async def debug_user_dict(current_user = Depends(get_current_user)):
    """返回model_dump结果"""
    user_schema = UserSchema.model_validate(current_user)
    return user_schema.model_dump()

if __name__ == "__main__":
    print("启动调试API服务器...")
    uvicorn.run(app, host="0.0.0.0", port=8001)
