"""Booking model.""" from datetime import datetime from sqlalchemy import Column, DateTime, ForeignKey, Integer, String from sqlalchemy.orm import relationship from app.db.session import Base class Booking(Base): """Booking model for space reservations.""" __tablename__ = "bookings" id = Column(Integer, primary_key=True, index=True) user_id = Column(Integer, ForeignKey("users.id"), nullable=False, index=True) space_id = Column(Integer, ForeignKey("spaces.id"), nullable=False, index=True) title = Column(String, nullable=False) description = Column(String, nullable=True) start_datetime = Column(DateTime, nullable=False, index=True) end_datetime = Column(DateTime, nullable=False, index=True) status = Column( String, nullable=False, default="pending", index=True ) # pending/approved/rejected/canceled rejection_reason = Column(String, nullable=True) cancellation_reason = Column(String, nullable=True) approved_by = Column(Integer, ForeignKey("users.id"), nullable=True) google_calendar_event_id = Column(String, nullable=True) # Store Google Calendar event ID created_at = Column(DateTime, nullable=False, default=datetime.utcnow) # Relationships user = relationship("User", foreign_keys=[user_id], backref="bookings") space = relationship("Space", foreign_keys=[space_id], backref="bookings") approver = relationship("User", foreign_keys=[approved_by], backref="approved_bookings") notifications = relationship("Notification", back_populates="booking") attachments = relationship("Attachment", back_populates="booking", cascade="all, delete-orphan")