from datetime import datetime, timezone
from sqlalchemy import Boolean, Column, DateTime, String
from sqlalchemy.dialects.postgresql import JSONB
from database.postgres import Base


def _now():
    return datetime.now(timezone.utc)


class Staff(Base):
    __tablename__ = "staff"

    id              = Column(String(128), primary_key=True)   # Firestore doc ID during transition
    firestore_id    = Column(String(128), unique=True)        # same as id during transition
    email           = Column(String(256), unique=True, nullable=False)
    name            = Column(String(255), nullable=False)
    role            = Column(String(64), nullable=False, default="staff")
    permissions     = Column(JSONB, nullable=True)
    hashed_password = Column(String(256), nullable=False)
    is_active       = Column(Boolean, nullable=False, default=True)
    ui_prefs        = Column(JSONB, nullable=False, default=dict)
    created_at      = Column(DateTime(timezone=True), nullable=False, default=_now)
    updated_at      = Column(DateTime(timezone=True), nullable=False, default=_now, onupdate=_now)
