from sqlalchemy import Column, Integer, DateTime, Numeric, Text, ForeignKey
from sqlalchemy.orm import relationship
from datetime import datetime
from ...shared.config.database import Base

class CheckInCheckOut(Base):
    __tablename__ = 'checkin_checkout'
    id = Column(Integer, primary_key=True, index=True, autoincrement=True)
    booking_id = Column(Integer, ForeignKey('bookings.id'), nullable=False, unique=True)
    checkin_time = Column(DateTime, nullable=True)
    checkout_time = Column(DateTime, nullable=True)
    checkin_by = Column(Integer, ForeignKey('users.id'), nullable=True)
    checkout_by = Column(Integer, ForeignKey('users.id'), nullable=True)
    room_condition_checkin = Column(Text, nullable=True)
    room_condition_checkout = Column(Text, nullable=True)
    additional_charges = Column(Numeric(10, 2), nullable=False, default=0.0)
    notes = Column(Text, nullable=True)
    created_at = Column(DateTime, default=datetime.utcnow, nullable=False)
    updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False)
    booking = relationship('Booking', back_populates='checkin_checkout')
    checked_in_by = relationship('User', foreign_keys=[checkin_by], back_populates='checkins_processed')
    checked_out_by = relationship('User', foreign_keys=[checkout_by], back_populates='checkouts_processed')