"""User model for VoIdea.""" from datetime import datetime from typing import Any, Optional from sqlalchemy import Boolean, DateTime, String, Text from sqlalchemy.dialects.postgresql import JSONB, UUID from sqlalchemy.orm import Mapped, mapped_column, relationship from app.core.base import SQLBase, TimestampMixin, UUIDMixin class User(SQLBase, UUIDMixin, TimestampMixin): __tablename__ = "users" email: Mapped[str] = mapped_column( String(255), unique=True, index=True, nullable=False ) password_hash: Mapped[Optional[str]] = mapped_column( String(255), nullable=True ) display_name: Mapped[str] = mapped_column( String(255), nullable=False ) avatar_url: Mapped[Optional[str]] = mapped_column( String(512), nullable=True ) is_active: Mapped[bool] = mapped_column( Boolean, default=True, nullable=False ) is_superuser: Mapped[bool] = mapped_column( Boolean, default=False, nullable=False ) # v2.0 role system role: Mapped[str] = mapped_column( String(20), default="user", nullable=False, index=True ) is_owner: Mapped[bool] = mapped_column( Boolean, default=False, nullable=False ) permissions: Mapped[Optional[dict[str, Any]]] = mapped_column( JSONB, nullable=True, default=None ) accepted_terms_at: Mapped[Optional[datetime]] = mapped_column( nullable=True ) accepted_terms_version: Mapped[Optional[str]] = mapped_column( String(20), nullable=True ) pipeline_tuning: Mapped[Optional[dict[str, Any]]] = mapped_column( JSONB, nullable=True, default=None ) oauth_provider: Mapped[Optional[str]] = mapped_column( String(50), nullable=True ) oauth_id: Mapped[Optional[str]] = mapped_column( String(255), nullable=True ) calendar_provider: Mapped[Optional[str]] = mapped_column( String(20), nullable=True, default=None ) calendar_credentials: Mapped[Optional[str]] = mapped_column( Text, nullable=True, default=None ) disk_providers: Mapped[Optional[list[dict[str, Any]]]] = mapped_column( JSONB, nullable=True, default=None ) ideas = relationship("Idea", back_populates="user", lazy="selectin")