from typing import List, Optional
from datetime import datetime
from sqlalchemy import Column, Integer, String, Float, ForeignKey, DateTime
from sqlalchemy.orm import relationship
from sqlalchemy.sql import func
from app.db.database import Base


class Card(Base):
    __tablename__ = "cards"

    id = Column(Integer, primary_key=True, index=True)
    name = Column(String, index=True)
    rarity = Column(String)
    set_name = Column(String, index=True)
    price = Column(Float)
    quantity = Column(Integer, default=0)
    
    # TCGPlayer specific fields
    tcgplayer_sku = Column(String, unique=True, index=True)
    product_line = Column(String)
    product_name = Column(String)
    title = Column(String)
    number = Column(String)
    condition = Column(String)
    tcg_market_price = Column(Float)
    tcg_direct_low = Column(Float)
    tcg_low_price_with_shipping = Column(Float)
    tcg_low_price = Column(Float)
    total_quantity = Column(Integer)
    add_to_quantity = Column(Integer)
    tcg_marketplace_price = Column(Float)
    photo_url = Column(String)
    
    # Timestamps
    created_at = Column(DateTime(timezone=True), server_default=func.now())
    updated_at = Column(DateTime(timezone=True), onupdate=func.now())
