"""
SQLAlchemy ORM model for user card imports.

This model corresponds to the user_card_imports table created in migration 004.
It stores a user's imported card collection as a JSON array of card names.
"""
from sqlalchemy import (
    Column, Integer, String, BigInteger, DateTime, Text,
    ForeignKey, UniqueConstraint
)
from sqlalchemy.orm import relationship
from sqlalchemy.sql import func
from app.core.database import Base


class UserCardImport(Base):
    """
    User card import record.
    
    Stores a user's imported card collection as a JSON array of card names.
    This table was created in migration 004 and may be superseded by
    CardImportBatch and UserCardImportRecord in migration 005.
    """
    __tablename__ = "user_card_imports"
    
    id = Column(Integer, primary_key=True, autoincrement=True)
    user_id = Column(Integer, ForeignKey("mtgonline_users.id", ondelete="CASCADE"), nullable=False)
    card_names_json = Column(Text, nullable=False)  # JSON array of card names
    created_at = Column(DateTime, server_default=func.now())
    updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now())
    
    # Relationships
    user = relationship("User", backref="card_imports")
    
    __table_args__ = (
        UniqueConstraint('user_id', name='uq_user_card_imports_user_id'),
    )
    
    def __repr__(self) -> str:
        return f"<UserCardImport user={self.user_id}>"
