from datetime import datetime

from sqlalchemy import DateTime, ForeignKey, Integer
from sqlalchemy.orm import Mapped, mapped_column
from sqlalchemy.sql import func


class BaseTimestampMixin:
    """Mixin for basic timestamp fields (no soft delete)"""

    created_at: Mapped[datetime] = mapped_column(
        DateTime, nullable=False, server_default=func.now()
    )
    updated_at: Mapped[datetime] = mapped_column(
        DateTime, nullable=False, server_default=func.now(), onupdate=func.now()
    )


class TimestampMixin(BaseTimestampMixin):
    """Mixin for common timestamp fields including soft delete"""

    deleted_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)


class TenantScopedMixin:
    """Mixin para entidades multi-tenant.

    company_id no tiene FK declarada aquí — agrégala en cada modelo
    apuntando a la tabla de compañías de tu proyecto.
    """

    tenant_id: Mapped[int] = mapped_column(Integer, ForeignKey("core.tenants.id"), nullable=False, index=True)
    company_id: Mapped[int] = mapped_column(Integer, nullable=False, index=True)
