from sqlalchemy import Column, String, Boolean, DateTime, Enum, Text
from sqlalchemy.sql import func
from database import Base
import enum

class Role(str, enum.Enum):
    SUPERADMIN   = "SUPERADMIN"
    ADMIN        = "ADMIN"
    CLIENT_ADMIN = "CLIENT_ADMIN"   # company-scoped: can start/stop recordings for own aids
    USER         = "USER"           # company-scoped: read-only

class User(Base):
    __tablename__ = "users"

    id          = Column(String, primary_key=True)
    username    = Column(String, unique=True, nullable=False)
    nombre      = Column(String, nullable=False)
    email       = Column(String, unique=True, nullable=True)
    hashed_pw   = Column(String, nullable=False)
    role        = Column(String, default="USER")
    company_id  = Column(String, nullable=True)
    activo      = Column(Boolean, default=True)
    creado_en   = Column(DateTime, server_default=func.now())
    ultimo_login = Column(DateTime, nullable=True)
    prefs_json   = Column(Text, nullable=True, default='{}')
