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

class RoomStatus(str, enum.Enum):
    available = 'available'
    occupied = 'occupied'
    maintenance = 'maintenance'
    cleaning = 'cleaning'

class Room(Base):
    __tablename__ = 'rooms'
    id = Column(Integer, primary_key=True, index=True, autoincrement=True)
    room_type_id = Column(Integer, ForeignKey('room_types.id'), nullable=False)
    room_number = Column(String(20), unique=True, nullable=False, index=True)
    floor = Column(Integer, nullable=False)
    status = Column(Enum(RoomStatus), nullable=False, default=RoomStatus.available)
    price = Column(Numeric(10, 2), nullable=False)
    featured = Column(Boolean, nullable=False, default=False)
    capacity = Column(Integer, nullable=True)
    room_size = Column(String(50), nullable=True)
    view = Column(String(100), nullable=True)
    images = Column(JSON, nullable=True)
    amenities = Column(JSON, nullable=True)
    description = 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)
    room_type = relationship('RoomType', back_populates='rooms')
    bookings = relationship('Booking', back_populates='room')
    reviews = relationship('Review', back_populates='room')
    favorites = relationship('Favorite', back_populates='room', cascade='all, delete-orphan')
    maintenance_records = relationship('RoomMaintenance', back_populates='room', cascade='all, delete-orphan')
    housekeeping_tasks = relationship('HousekeepingTask', back_populates='room', cascade='all, delete-orphan')
    inspections = relationship('RoomInspection', back_populates='room', cascade='all, delete-orphan')
    attributes = relationship('RoomAttribute', back_populates='room', cascade='all, delete-orphan')