from sqlalchemy import Boolean, ForeignKey, Integer, String, Text, text from sqlalchemy.orm import Mapped, mapped_column from api.v1.common.base_models import TenantScopedMixin, TimestampMixin from core.database import Base class Contact(Base, TenantScopedMixin, TimestampMixin): """Contacto CRM: persona asociada (opcionalmente) a una cuenta.""" __tablename__ = "contacts" __table_args__ = {"schema": "crm"} id: Mapped[int] = mapped_column(Integer, primary_key=True, index=True) account_id: Mapped[int | None] = mapped_column( Integer, ForeignKey("crm.accounts.id"), nullable=True, index=True ) first_name: Mapped[str] = mapped_column(String(120), nullable=False) last_name: Mapped[str | None] = mapped_column(String(120), nullable=True) email: Mapped[str | None] = mapped_column(String(255), nullable=True, index=True) phone: Mapped[str | None] = mapped_column(String(40), nullable=True) mobile: Mapped[str | None] = mapped_column(String(40), nullable=True) job_title: Mapped[str | None] = mapped_column(String(120), nullable=True) department: Mapped[str | None] = mapped_column(String(120), nullable=True) is_primary: Mapped[bool] = mapped_column(Boolean, nullable=False, server_default=text("false")) owner_user_id: Mapped[str | None] = mapped_column(String(64), nullable=True, index=True) notes: Mapped[str | None] = mapped_column(Text, nullable=True)