"""
SQLAlchemy ORM model for user card imports.

Stores a user's imported card collection as a JSON string containing
a list of card names. This is the source data for building decks
from the user's actual card collection.
"""
from sqlalchemy import Column, Integer, String, DateTime, ForeignKey, Text, UniqueConstraint
from sqlalchemy.orm import relationship
from sqlalchemy.sql import func
from app.core.database import Base


class UserCardImport(Base):
    """
    User's imported card collection.
    
    Stores a JSON string of card names that the user owns.
    Used as the source for building decks from user's actual cards.
    """
    __tablename__ = "user_card_imports"

    id = Column(Integer, primary_key=True, autoincrement=True)
    user_id = Column(Integer, ForeignKey("mtgonline_users.id", ondelete="CASCADE"), nullable=False, unique=True, index=True)
    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")

    def __repr__(self) -> str:
        return f"<UserCardImport user={self.user_id}>"
