from __future__ import annotations


from sqlalchemy import Column, DateTime, ForeignKey, Integer, String, Text
from sqlalchemy.sql import func

from config.database import Base


class ImportExportLog(Base):
    """Audit log for import and export operations."""

    __tablename__ = "import_export_logs"

    id = Column(Integer, primary_key=True, index=True)
    action = Column(String(32), nullable=False)  # preview, commit, export
    dataset = Column(String(32), nullable=False)  # projects, scenarios, etc.
    status = Column(String(16), nullable=False)  # success, failure
    filename = Column(String(255), nullable=True)
    row_count = Column(Integer, nullable=True)
    detail = Column(Text, nullable=True)
    user_id = Column(Integer, ForeignKey("users.id"), nullable=True)
    created_at = Column(
        DateTime(timezone=True), nullable=False, server_default=func.now()
    )

    def __repr__(self) -> str:  # pragma: no cover
        return (
            f"ImportExportLog(id={self.id}, action={self.action}, "
            f"dataset={self.dataset}, status={self.status})"
        )
