from sqlalchemy import Column, String, Enum, DateTime,Boolean,Integer
from sqlalchemy.ext.declarative import declarative_base
from src.constants import ApplicationUserRoleEnum
from datetime import datetime,timezone
from src.core.utils import generate_uuid
from src.core.database import Base
from sqlalchemy.sql import func




class ApplicationUser(Base):
    __tablename__ = "application_users"  # application-level admins,

    id = Column(String, primary_key=True, default=generate_uuid)
    email = Column(String, unique=True, nullable=False)
    hashed_password = Column(String, nullable=False)
    full_name = Column(String, nullable=False)
    role = Column(Enum(ApplicationUserRoleEnum), nullable=False)

    is_account_active = Column(Boolean, default=True)
    created_at = Column(DateTime(timezone=True), default=func.now(), nullable=False)
    updated_at = Column(DateTime(timezone=True), onupdate=func.now(), nullable=True)

    is_2FA_required = Column(Boolean, default=False,nullable=False)
    is_2FA_enabled     = Column(Boolean, default=False,nullable=False)
    temp_2fa_secret   = Column(String(100),default=None ,nullable=True)
    secret_2fa     = Column(String(100),default=None, nullable=True)
    failed_login_attempts = Column(Integer, default=0, nullable=False)
    is_account_locked = Column(Boolean, default=False)# lock the account once 5 login attemts faild even for admin



