from sqlalchemy import Column, Float, Integer, String, ForeignKey, Text from core.timeutil import UTCDateTime, utcnow from sqlalchemy.orm import relationship from database import Base class Reservation(Base): __tablename__ = "reservations" id = Column(Integer, primary_key=True, index=True) # Guest info guest_name = Column(String, nullable=False) party_size = Column(Integer, nullable=False) phone = Column(String, nullable=True) email = Column(String, nullable=True) note = Column(Text, nullable=True) # When the customer wants the table reserved_for = Column(UTCDateTime, nullable=False) # Optional table assignment (assignable/editable later) table_id = Column(Integer, ForeignKey("tables.id"), nullable=True) # Lifecycle: pending (confirmed, upcoming) | arrived | cancelled | no_show; # online requests (phase 3S, S.6) start as requested → pending (confirmed) | declined status = Column(String, nullable=False, default="pending") # Source: manager_app | waiter_app | online source = Column(String, nullable=False, default="manager_app") # Who entered this reservation (staff user) created_by_user_id = Column(Integer, ForeignKey("users.id"), nullable=True) # For future online reservations: cloud-side customer identifier online_customer_id = Column(String, nullable=True) # Online bookings (phase 3S, S.6): the cloud's order (status mirrored to the customer's page) online_order_cloud_id = Column(Integer, nullable=True, index=True) online_ref = Column(String, nullable=True) # "ORD-0042" # food ordered ahead: the cloud's lines (its prices) until the kitchen gets them, then the order items_json = Column(Text, nullable=True) # JSON list as the cloud sent it; NULL = a table only total = Column(Float, nullable=True) online_price_diff = Column(Text, nullable=True) # services/online_check.py; NULL = matched fire_at = Column(UTCDateTime, nullable=True) # when the kitchen gets the food (set on confirming) order_id = Column(Integer, ForeignKey("orders.id"), nullable=True) # created at fire time response_note = Column(Text, nullable=True) # why it was declined / cancelled (the customer sees it) created_at = Column(UTCDateTime, default=utcnow) updated_at = Column(UTCDateTime, default=utcnow, onupdate=utcnow) table = relationship("Table", foreign_keys=[table_id]) order = relationship("Order", foreign_keys=[order_id]) created_by = relationship("User", foreign_keys=[created_by_user_id])