# from datetime import datetime
# from fastapi import HTTPException
# from fastapi.security import OAuth2PasswordRequestForm

# from sqlalchemy.orm import Session

# from app.api.auth import schemas
# from app.dependency.authantication import JWTManager, JWTPayloadSchema
# from app.models.main.student import StudentBase, TblStudent

# from app.utils.schemas_utils import CustomResponse  # Import custom response utility

# class AuthService:
#     def __init__(self, db: Session):
#         self.db = db  # Initialize with the database session

#     async def create_student(self, request: schemas.UserCreate):
#         created_student = StudentBase.model_validate(request)  # Validate and create user model
#         TblStudent.create(created_student, self.db)  # Insert user into the database
#         self.db.commit()  # Commit the transaction
#         return CustomResponse(status="1", message="User created successfully")  # Return success response

    
    
#     # async def update_user(self, request: schemas.UserUpdate):
#     #     updated_user = UsersBase.model_validate(request)  # Validate and create updated user model
#     #     if updated_user.usr_id is None:
#     #         return CustomResponse(status="-1", message="User id not found")  # Return error if user ID is missing
#     #     TblUsers.update(updated_user.usr_id, updated_user, self.db)  # Update user in the database
#     #     self.db.commit()  # Commit the transaction
#     #     return CustomResponse(status="1", message="User updated successfully")  # Return success response
    
#     @staticmethod
#     async def student_login(credentials: OAuth2PasswordRequestForm, db: Session):
#         student = TblStudent.get_by_student_email(credentials.username, db)

#         if not student:
#             raise HTTPException(status_code=404, detail="Student not found")  # ✅ use raise

#         if credentials.password != student.password:
#             raise HTTPException(status_code=401, detail="Incorrect password")  # ✅ use raise

#         payload = JWTPayloadSchema(
#             user_id=student.student_id,
#             user_type="student",  # ✅ hardcoded or pull from DB if available
#             user_role=student.role.strip(),
#             exp=datetime.utcnow()  # will be replaced inside `create_access_token`
#         )

#         access_token = JWTManager.create_access_token(payload)

#         return {
#             "access_token": access_token,
#             "token_type": "bearer",
#             "email_id": student.student_email,
#             "role": student.role.strip()
#         }