from sqlalchemy import Column, Integer, String, Float, DateTime, JSON, ForeignKey
from sqlalchemy.sql import func
from app.db.database import Base
from sqlalchemy.orm import relationship

class TCGPlayerOrder(Base):
    __tablename__ = "tcgplayer_orders"

    id = Column(Integer, primary_key=True, index=True)
    order_number = Column(String, index=True)
    order_created_at = Column(DateTime(timezone=True))
    status = Column(String)
    channel = Column(String)
    fulfillment = Column(String)
    seller_name = Column(String)
    buyer_name = Column(String)
    payment_type = Column(String)
    pickup_status = Column(String)
    shipping_type = Column(String)
    estimated_delivery_date = Column(DateTime(timezone=True))
    recipient_name = Column(String)
    address_line_1 = Column(String)
    address_line_2 = Column(String)
    city = Column(String)
    state = Column(String)
    zip_code = Column(String)
    country = Column(String)
    tracking_numbers = Column(JSON)
    created_at = Column(DateTime(timezone=True), server_default=func.now())
    updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())


class TCGPlayerOrderTransaction(Base):
    __tablename__ = "tcgplayer_order_transactions"

    id = Column(Integer, primary_key=True, index=True)
    order_number = Column(String, index=True)
    product_amount = Column(Float)
    shipping_amount = Column(Float)
    gross_amount = Column(Float)
    fee_amount = Column(Float)
    net_amount = Column(Float)
    direct_fee_amount = Column(Float)
    taxes = Column(JSON)
    created_at = Column(DateTime(timezone=True), server_default=func.now())
    updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())   


class TCGPlayerOrderProduct(Base):
    __tablename__ = "tcgplayer_order_products"

    id = Column(Integer, primary_key=True, index=True)
    order_number = Column(String, index=True)
    product_name = Column(String)
    unit_price = Column(Float)
    extended_price = Column(Float)
    quantity = Column(Integer)
    url = Column(String)
    product_id = Column(Integer)
    sku_id = Column(Integer)
    created_at = Column(DateTime(timezone=True), server_default=func.now())
    updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())


class TCGPlayerOrderRefund(Base):
    __tablename__ = "tcgplayer_order_refunds"

    id = Column(Integer, primary_key=True, index=True)
    order_number = Column(String, index=True)
    refund_created_at = Column(DateTime(timezone=True))
    type = Column(String)
    amount = Column(Float)
    type = Column(String)
    description = Column(String)
    origin = Column(String)
    shipping_amount = Column(Float)
    products = Column(JSON)
    created_at = Column(DateTime(timezone=True), server_default=func.now())
    updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
