from datetime import datetime

from sqlalchemy import DateTime, Float, String, func
from sqlalchemy.orm import Mapped, mapped_column, relationship

from app.core.database import Base


class OrderBatch(Base):
    __tablename__ = "ordini_batches"

    id: Mapped[int] = mapped_column(primary_key=True, index=True)
    staff: Mapped[str] = mapped_column(String(80), nullable=False, index=True)
    total_estimated_amount: Mapped[float | None] = mapped_column(Float, nullable=True)
    confirmed_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now(), nullable=False, index=True)

    items = relationship("OrderItem", back_populates="batch", cascade="all, delete-orphan", order_by="OrderItem.id")
