"""
Client model for hotel guests.
"""
from sqlalchemy import Column, String, Text, Date, Boolean
from sqlalchemy.orm import relationship

from app.models.base import BaseModel


class Client(BaseModel):
    """
    Hotel guest/client information.

    Attributes:
        first_name: Client's first name
        last_name: Client's last name
        email: Email address
        phone: Phone number
        mobile: Mobile phone number
        address: Street address
        city: City
        postal_code: Postal code
        country: Country
        nationality: Nationality
        id_type: Type of ID document
        id_number: ID document number
        id_expiry: ID expiry date
        date_of_birth: Birth date
        company_name: Company name (for business clients)
        tax_id: Client's tax ID
        notes: Internal notes
        vip: VIP status flag
        blacklisted: Blacklist flag
    """
    __tablename__ = "clients"

    # Personal information
    first_name = Column(String(100), nullable=False)
    last_name = Column(String(100), nullable=False)
    email = Column(String(255), nullable=True, index=True)
    phone = Column(String(50), nullable=True)
    mobile = Column(String(50), nullable=True)

    # Address
    address = Column(Text, nullable=True)
    city = Column(String(100), nullable=True)
    postal_code = Column(String(20), nullable=True)
    country = Column(String(100), nullable=True)

    # Identity
    nationality = Column(String(100), nullable=True)
    id_type = Column(String(50), nullable=True)
    id_number = Column(String(100), nullable=True, index=True)
    id_expiry = Column(Date, nullable=True)
    date_of_birth = Column(Date, nullable=True)

    # Business information
    company_name = Column(String(200), nullable=True)
    tax_id = Column(String(100), nullable=True)

    # Status flags
    notes = Column(Text, nullable=True)
    vip = Column(Boolean, default=False, nullable=False)
    blacklisted = Column(Boolean, default=False, nullable=False)
    is_active = Column(Boolean, default=True, nullable=False)

    # Relationships
    reservations = relationship("Reservation", back_populates="client")
    notifications = relationship("Notification", back_populates="client")
    documents = relationship("Document", back_populates="client", cascade="all, delete-orphan")
    waitlist_entries = relationship("Waitlist", back_populates="client")
    loyalty_membership = relationship("LoyaltyMembership", back_populates="client", uselist=False)

    @property
    def full_name(self) -> str:
        """Return client's full name."""
        return f"{self.first_name} {self.last_name}"

    @property
    def display_name(self) -> str:
        """Return display name (with company if available)."""
        if self.company_name:
            return f"{self.full_name} ({self.company_name})"
        return self.full_name

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