from core.database import Base
from datetime import datetime
from sqlalchemy import Column, DateTime, Float, Integer, String


class Orders(Base):
    __tablename__ = "orders"
    __table_args__ = {"extend_existing": True}

    id = Column(Integer, primary_key=True, index=True, autoincrement=True, nullable=False)
    user_id = Column(String, nullable=False)
    order_number = Column(String, nullable=False)
    status = Column(String, nullable=False)
    payment_status = Column(String, nullable=True)
    subtotal = Column(Float, nullable=True)
    shipping_cost = Column(Float, nullable=True)
    tax = Column(Float, nullable=True)
    total = Column(Float, nullable=True)
    currency = Column(String, nullable=True)
    items_json = Column(String, nullable=True)
    shipping_address_json = Column(String, nullable=True)
    billing_email = Column(String, nullable=True)
    stripe_session_id = Column(String, nullable=True)
    payment_method = Column(String, nullable=True)
    tracking_number = Column(String, nullable=True)
    # Last DHL status we already notified the customer about. Used by the
    # shipment notification service to avoid sending duplicate emails for
    # the same status. ``None`` means the customer has never been notified
    # about this shipment yet.
    last_notified_status = Column(String, nullable=True)
    notes = Column(String, nullable=True)
    created_at = Column(DateTime(timezone=True), default=datetime.now)
    updated_at = Column(DateTime(timezone=True), default=datetime.now, onupdate=datetime.now)