"""
用户服务层
处理用户相关的业务逻辑
"""
import logging
from typing import Optional, Dict, List
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy import select
from app.models.user import User

logger = logging.getLogger(__name__)


class UserService:
    """用户服务类"""
    
    def __init__(self, session: AsyncSession):
        """初始化服务，接收数据库session"""
        self.session = session
    
    async def get_user_by_id(self, user_id: str) -> Optional[User]:
        """根据用户ID获取用户对象"""
        try:
            result = await self.session.execute(
                select(User).where(User.id == user_id)
            )
            user = result.scalar_one_or_none()
            return user
        except Exception as e:
            logger.error(f"根据ID获取用户失败: user_id={user_id}, error={str(e)}")
            return None
    
