from sqlalchemy import Boolean, ForeignKey, Integer, String, Text
from sqlalchemy.orm import Mapped, mapped_column, relationship

from app.core.database import Base


class Room(Base):
    __tablename__ = "rooms"

    id: Mapped[int] = mapped_column(primary_key=True, index=True)
    venue_id: Mapped[int] = mapped_column(ForeignKey("venues.id"), nullable=False, index=True)
    name: Mapped[str] = mapped_column(String(120), nullable=False)
    width: Mapped[int] = mapped_column(Integer, nullable=False)
    height: Mapped[int] = mapped_column(Integer, nullable=False)
    counter_name: Mapped[str | None] = mapped_column(String(120), nullable=True)
    counter_x: Mapped[int | None] = mapped_column(Integer, nullable=True)
    counter_y: Mapped[int | None] = mapped_column(Integer, nullable=True)
    counter_width: Mapped[int | None] = mapped_column(Integer, nullable=True)
    counter_height: Mapped[int | None] = mapped_column(Integer, nullable=True)
    counter_visible: Mapped[bool] = mapped_column(Boolean, nullable=False, default=True)
    entrance_name: Mapped[str | None] = mapped_column(String(120), nullable=True)
    entrance_x: Mapped[int | None] = mapped_column(Integer, nullable=True)
    entrance_y: Mapped[int | None] = mapped_column(Integer, nullable=True)
    entrance_width: Mapped[int | None] = mapped_column(Integer, nullable=True)
    entrance_height: Mapped[int | None] = mapped_column(Integer, nullable=True)
    entrance_visible: Mapped[bool] = mapped_column(Boolean, nullable=False, default=True)
    background_image_data_url: Mapped[str | None] = mapped_column(Text, nullable=True)

    venue = relationship("Venue", back_populates="rooms")
    tables = relationship("Table", back_populates="room", cascade="all, delete-orphan")
    combinations = relationship("TableCombination", back_populates="room", cascade="all, delete-orphan")
