from typing import TYPE_CHECKING

from sqlalchemy import String
from sqlalchemy.orm import Mapped, mapped_column, relationship

from src.models.base import Base, TimestampMixin, UUIDPrimaryKeyMixin

if TYPE_CHECKING:
    from src.models.project import Project
    from src.models import SSHKey
    from src.models import UserConfig


class User(UUIDPrimaryKeyMixin, TimestampMixin, Base):
    __tablename__ = "users"

    email: Mapped[str] = mapped_column(String(255), unique=True, index=True)
    name: Mapped[str] = mapped_column(String(255))
    authentik_id: Mapped[str] = mapped_column(String(255), unique=True, index=True)
    avatar_url: Mapped[str | None] = mapped_column(String(1024), nullable=True)

    projects: Mapped[list["Project"]] = relationship(back_populates="owner")
    ssh_keys: Mapped[list["SSHKey"]] = relationship(back_populates="user")
    user_config: Mapped["UserConfig | None"] = relationship(back_populates="user", uselist=False)
