from sqlalchemy import Column, Integer, String, DateTime, JSON, ForeignKey
from sqlalchemy.sql import func
from app.core.database import Base

class ImportLog(Base):
    __tablename__ = "import_logs"

    id = Column(Integer, primary_key=True, index=True)
    filename = Column(String(255), nullable=False)
    total_count = Column(Integer, default=0)
    success_count = Column(Integer, default=0)
    fail_count = Column(Integer, default=0)
    
    # Store detailed results, e.g., [{"row": 2, "error": "Mobile duplicate"}, ...]
    # Or [{"mobile": "...", "password": "..."}] for success export (be careful with sensitive data, maybe only store errors here and regenerate success file on demand? 
    # User said "Export successful results with account and initial password". 
    # We should probably store the success data temporarily or generated file path. 
    # Storing passwords in plain text in logs is bad practice, but required for "Export initial password". 
    # We can store an encrypted blob or just the result JSON if the requirement strictly asks for it. 
    # For now, let's store `details` as a generic JSON which can hold error logs. 
    # For the success export, we might generate it immediately and return it, or store the success data in this JSON field (encrypted ideally, but simple JSON for this task).
    result_data = Column(JSON, nullable=True) 
    
    created_by = Column(Integer, ForeignKey("users.id"), nullable=True)
    created_at = Column(DateTime(timezone=True), server_default=func.now())

