"""Pydantic schemas for ServiceBlock and ServiceBlockOverride CRUD endpoints."""

from datetime import date, time
from typing import Any

from sqlmodel import SQLModel

# ── ServiceBlock schemas ──────────────────────────────────────────────────────


class ServiceBlockCreate(SQLModel):
    day_of_week: int
    name: str
    block_type: str  # "open" | "closed"
    start_time: time
    end_time: time
    max_covers: int | None = None
    default_duration_minutes: int | None = None
    is_active: bool = True
    display_order: int = 0
    slot_interval_minutes: int = 30
    open_zone_ids: list[str] = []


class ServiceBlockUpdate(SQLModel):
    day_of_week: int
    name: str
    block_type: str
    start_time: time
    end_time: time
    max_covers: int | None = None
    default_duration_minutes: int | None = None
    is_active: bool = True
    display_order: int = 0
    slot_interval_minutes: int = 30
    open_zone_ids: list[str] = []


class ServiceBlockRead(SQLModel):
    id: str
    restaurant_id: str
    day_of_week: int
    name: str
    block_type: str
    start_time: time
    end_time: time
    max_covers: int | None = None
    default_duration_minutes: int | None = None
    is_active: bool
    display_order: int
    slot_interval_minutes: int = 30
    open_zone_ids: list[str] = []


# ── ServiceBlockOverride schemas ──────────────────────────────────────────────


class OverrideBlockDef(SQLModel):
    """A single block definition within an override — mirrors ServiceBlock fields."""

    name: str
    block_type: str  # "open" | "closed"
    start_time: time
    end_time: time
    max_covers: int | None = None
    default_duration_minutes: int | None = None
    slot_interval_minutes: int | None = 30
    open_zone_ids: list[str] | None = None


class ServiceBlockOverrideCreate(SQLModel):
    start_date: date
    end_date: date
    name: str
    blocks: list[dict[str, Any]] | None = None  # Each dict may include 'open_zone_ids'
    is_active: bool = True


class ServiceBlockOverrideUpdate(SQLModel):
    start_date: date
    end_date: date
    name: str
    blocks: list[dict[str, Any]] | None = None  # Each dict may include 'open_zone_ids'
    is_active: bool = True


class ServiceBlockOverrideRead(SQLModel):
    id: str
    restaurant_id: str
    start_date: date
    end_date: date
    name: str
    blocks: list[dict[str, Any]] | None = None  # Each dict may include 'open_zone_ids'
    is_active: bool
