

from fastapi import HTTPException
from sqlalchemy import select
from fastapi import status
from .service import  Service
from src.models.company_user import User
from src.models.application_user import ApplicationUser
from sqlalchemy.ext.asyncio import AsyncSession

class ApplicationService(Service):
    
    @staticmethod
    async def get_applicationuser_by_email(email: str, db: AsyncSession) -> User:
        stmt = select(ApplicationUser).where(ApplicationUser.email == email).limit(1)
        result = await db.execute(stmt)
        user = result.scalars().first()
        if not user:
            raise HTTPException(
                status_code=status.HTTP_404_NOT_FOUND,
                detail="User not found"
            )
        return user

    @staticmethod
    async def get_applicationuser_by_id(user_id:str,db:AsyncSession) -> User:
        stmt = select(ApplicationUser).where(User.id == user_id).limit(1)
        result = await db.execute(stmt)
        user = result.scalars().first()

        if not user:
            raise HTTPException(
                status_code=status.HTTP_404_NOT_FOUND,
                detail="User not found"
            )
        return user