"""
Establishment model for hotel/residence configuration.
"""
from sqlalchemy import Column, String, Integer, Text, Float
from sqlalchemy.orm import relationship

from app.models.base import BaseModel


class Establishment(BaseModel):
    """
    Hotel/Residence establishment configuration.

    Attributes:
        name: Establishment name
        address: Full address
        city: City name
        country: Country name
        phone: Contact phone
        email: Contact email
        website: Website URL
        capacity_rooms: Total number of rooms
        capacity_beds: Total number of beds
        currency: Default currency code (EUR, USD, etc.)
        tax_id: Tax identification number
        logo_url: Logo image URL
    """
    __tablename__ = "establishments"

    name = Column(String(200), nullable=False)
    address = Column(Text, nullable=True)
    city = Column(String(100), nullable=True)
    country = Column(String(100), nullable=True)
    postal_code = Column(String(20), nullable=True)
    phone = Column(String(50), nullable=True)
    email = Column(String(255), nullable=True)
    website = Column(String(255), nullable=True)
    capacity_rooms = Column(Integer, default=0, nullable=False)
    capacity_beds = Column(Integer, default=0, nullable=False)
    currency = Column(String(3), default="XOF", nullable=False)  # Franc CFA par défaut pour le Sénégal
    tax_id = Column(String(100), nullable=True)  # Ancien champ générique
    ninea = Column(String(50), nullable=True)  # NINEA (Sénégal)
    tva_number = Column(String(50), nullable=True)  # Numéro TVA
    logo_url = Column(String(500), nullable=True)
    default_checkin_time = Column(String(5), default="14:00", nullable=False)
    default_checkout_time = Column(String(5), default="11:00", nullable=False)

    # Relationships
    users = relationship("User", back_populates="establishment")
    room_types = relationship(
        "RoomType",
        back_populates="establishment",
        cascade="all, delete-orphan"
    )
    rooms = relationship(
        "Room",
        back_populates="establishment",
        cascade="all, delete-orphan"
    )
    daily_stats = relationship(
        "DailyStats",
        back_populates="establishment",
        cascade="all, delete-orphan"
    )
    notification_settings = relationship(
        "NotificationSetting",
        back_populates="establishment",
        uselist=False,
        cascade="all, delete-orphan"
    )
    budgets = relationship(
        "Budget",
        back_populates="establishment",
        cascade="all, delete-orphan"
    )
    waitlist = relationship(
        "Waitlist",
        back_populates="establishment",
        cascade="all, delete-orphan"
    )

    def __repr__(self) -> str:
        return f"<Establishment {self.name}>"
