"""
Establishment schemas for hotel configuration.
"""
from typing import Optional
from datetime import datetime
from pydantic import BaseModel, EmailStr, Field


class EstablishmentBase(BaseModel):
    """Base establishment schema."""
    name: str = Field(..., min_length=1, max_length=200)
    address: Optional[str] = None
    city: Optional[str] = Field(None, max_length=100)
    country: Optional[str] = Field(None, max_length=100)
    postal_code: Optional[str] = Field(None, max_length=20)
    phone: Optional[str] = Field(None, max_length=50)
    email: Optional[EmailStr] = None
    website: Optional[str] = Field(None, max_length=255)
    capacity_rooms: int = Field(0, ge=0)
    capacity_beds: int = Field(0, ge=0)
    currency: str = Field("XOF", max_length=3)
    tax_id: Optional[str] = Field(None, max_length=100)
    logo_url: Optional[str] = Field(None, max_length=500)
    default_checkin_time: str = Field("14:00", pattern=r"^\d{2}:\d{2}$")
    default_checkout_time: str = Field("11:00", pattern=r"^\d{2}:\d{2}$")


class EstablishmentCreate(EstablishmentBase):
    """Schema for creating an establishment."""
    pass


class EstablishmentUpdate(BaseModel):
    """Schema for updating an establishment."""
    name: Optional[str] = Field(None, min_length=1, max_length=200)
    address: Optional[str] = None
    city: Optional[str] = Field(None, max_length=100)
    country: Optional[str] = Field(None, max_length=100)
    postal_code: Optional[str] = Field(None, max_length=20)
    phone: Optional[str] = Field(None, max_length=50)
    email: Optional[EmailStr] = None
    website: Optional[str] = Field(None, max_length=255)
    capacity_rooms: Optional[int] = Field(None, ge=0)
    capacity_beds: Optional[int] = Field(None, ge=0)
    currency: Optional[str] = Field(None, max_length=3)
    tax_id: Optional[str] = Field(None, max_length=100)
    logo_url: Optional[str] = Field(None, max_length=500)
    default_checkin_time: Optional[str] = Field(None, pattern=r"^\d{2}:\d{2}$")
    default_checkout_time: Optional[str] = Field(None, pattern=r"^\d{2}:\d{2}$")


class EstablishmentResponse(EstablishmentBase):
    """Schema for establishment response."""
    id: int
    created_at: datetime
    updated_at: datetime

    class Config:
        from_attributes = True


class EstablishmentStats(BaseModel):
    """Quick stats for an establishment."""
    total_rooms: int
    available_rooms: int
    occupied_rooms: int
    today_arrivals: int
    today_departures: int
    in_house_guests: int
