from sqlalchemy import Column, Integer, String, Text, ForeignKey, DateTime, Enum, Boolean
from sqlalchemy.orm import relationship
from datetime import datetime
import enum
from ...shared.config.database import Base

class CommunicationType(str, enum.Enum):
    email = 'email'
    phone = 'phone'
    sms = 'sms'
    chat = 'chat'
    in_person = 'in_person'
    other = 'other'

class CommunicationDirection(str, enum.Enum):
    inbound = 'inbound'  # Guest to hotel
    outbound = 'outbound'  # Hotel to guest

class GuestCommunication(Base):
    __tablename__ = 'guest_communications'
    id = Column(Integer, primary_key=True, index=True, autoincrement=True)
    user_id = Column(Integer, ForeignKey('users.id'), nullable=False, index=True)
    staff_id = Column(Integer, ForeignKey('users.id'), nullable=True)  # Staff member who handled communication
    communication_type = Column(Enum(CommunicationType), nullable=False)
    direction = Column(Enum(CommunicationDirection), nullable=False)
    subject = Column(String(255), nullable=True)
    content = Column(Text, nullable=False)
    booking_id = Column(Integer, ForeignKey('bookings.id'), nullable=True)  # Related booking if applicable
    is_automated = Column(Boolean, nullable=False, default=False)  # If this was an automated communication
    communication_metadata = Column(Text, nullable=True)  # JSON string for additional data
    created_at = Column(DateTime, default=datetime.utcnow, nullable=False)
    
    user = relationship('User', foreign_keys=[user_id], back_populates='guest_communications')
    staff = relationship('User', foreign_keys=[staff_id])
    booking = relationship('Booking')

