"""
Auto-generated queue resource.

DO NOT EDIT THIS FILE MANUALLY.
Run `python scripts/generate_resources.py` to regenerate.
"""

from __future__ import annotations

from typing import TYPE_CHECKING, Any

if TYPE_CHECKING:
    from ..client.base import BaseClient


class QueueResource:
    """
    Manage posting queue and time slots.
    """

    def __init__(self, client: BaseClient) -> None:
        self._client = client

    def _build_params(self, **kwargs: Any) -> dict[str, Any]:
        """Build query parameters, filtering None values."""

        def to_camel(s: str) -> str:
            parts = s.split("_")
            return parts[0] + "".join(p.title() for p in parts[1:])

        return {to_camel(k): v for k, v in kwargs.items() if v is not None}

    def _build_payload(self, **kwargs: Any) -> dict[str, Any]:
        """Build request payload, filtering None values."""
        from datetime import datetime

        def to_camel(s: str) -> str:
            parts = s.split("_")
            return parts[0] + "".join(p.title() for p in parts[1:])

        result: dict[str, Any] = {}
        for k, v in kwargs.items():
            if v is None:
                continue
            if isinstance(v, datetime):
                result[to_camel(k)] = v.isoformat()
            else:
                result[to_camel(k)] = v
        return result

    def list_queue_slots(
        self, profile_id: str, *, queue_id: str | None = None, all: str | None = None
    ) -> dict[str, Any]:
        """List schedules"""
        params = self._build_params(
            profile_id=profile_id,
            queue_id=queue_id,
            all=all,
        )
        return self._client._get("/v1/queue/slots", params=params)

    def create_queue_slot(
        self,
        profile_id: str,
        name: str,
        timezone: str,
        slots: list[Any],
        *,
        active: bool | None = True,
    ) -> dict[str, Any]:
        """Create schedule"""
        payload = self._build_payload(
            profile_id=profile_id,
            name=name,
            timezone=timezone,
            slots=slots,
            active=active,
        )
        return self._client._post("/v1/queue/slots", data=payload)

    def update_queue_slot(
        self,
        profile_id: str,
        timezone: str,
        slots: list[Any],
        *,
        queue_id: str | None = None,
        name: str | None = None,
        active: bool | None = True,
        set_as_default: bool | None = None,
        reshuffle_existing: bool | None = False,
    ) -> dict[str, Any]:
        """Update schedule"""
        payload = self._build_payload(
            profile_id=profile_id,
            queue_id=queue_id,
            name=name,
            timezone=timezone,
            slots=slots,
            active=active,
            set_as_default=set_as_default,
            reshuffle_existing=reshuffle_existing,
        )
        return self._client._put("/v1/queue/slots", data=payload)

    def delete_queue_slot(self, profile_id: str, queue_id: str) -> dict[str, Any]:
        """Delete schedule"""
        params = self._build_params(
            profile_id=profile_id,
            queue_id=queue_id,
        )
        return self._client._delete("/v1/queue/slots", params=params)

    def preview_queue(
        self, profile_id: str, *, queue_id: str | None = None, count: int | None = 20
    ) -> dict[str, Any]:
        """Preview upcoming slots"""
        params = self._build_params(
            profile_id=profile_id,
            queue_id=queue_id,
            count=count,
        )
        return self._client._get("/v1/queue/preview", params=params)

    def get_next_queue_slot(
        self, profile_id: str, *, queue_id: str | None = None
    ) -> dict[str, Any]:
        """Get next available slot"""
        params = self._build_params(
            profile_id=profile_id,
            queue_id=queue_id,
        )
        return self._client._get("/v1/queue/next-slot", params=params)

    async def alist_queue_slots(
        self, profile_id: str, *, queue_id: str | None = None, all: str | None = None
    ) -> dict[str, Any]:
        """List schedules (async)"""
        params = self._build_params(
            profile_id=profile_id,
            queue_id=queue_id,
            all=all,
        )
        return await self._client._aget("/v1/queue/slots", params=params)

    async def acreate_queue_slot(
        self,
        profile_id: str,
        name: str,
        timezone: str,
        slots: list[Any],
        *,
        active: bool | None = True,
    ) -> dict[str, Any]:
        """Create schedule (async)"""
        payload = self._build_payload(
            profile_id=profile_id,
            name=name,
            timezone=timezone,
            slots=slots,
            active=active,
        )
        return await self._client._apost("/v1/queue/slots", data=payload)

    async def aupdate_queue_slot(
        self,
        profile_id: str,
        timezone: str,
        slots: list[Any],
        *,
        queue_id: str | None = None,
        name: str | None = None,
        active: bool | None = True,
        set_as_default: bool | None = None,
        reshuffle_existing: bool | None = False,
    ) -> dict[str, Any]:
        """Update schedule (async)"""
        payload = self._build_payload(
            profile_id=profile_id,
            queue_id=queue_id,
            name=name,
            timezone=timezone,
            slots=slots,
            active=active,
            set_as_default=set_as_default,
            reshuffle_existing=reshuffle_existing,
        )
        return await self._client._aput("/v1/queue/slots", data=payload)

    async def adelete_queue_slot(
        self, profile_id: str, queue_id: str
    ) -> dict[str, Any]:
        """Delete schedule (async)"""
        params = self._build_params(
            profile_id=profile_id,
            queue_id=queue_id,
        )
        return await self._client._adelete("/v1/queue/slots", params=params)

    async def apreview_queue(
        self, profile_id: str, *, queue_id: str | None = None, count: int | None = 20
    ) -> dict[str, Any]:
        """Preview upcoming slots (async)"""
        params = self._build_params(
            profile_id=profile_id,
            queue_id=queue_id,
            count=count,
        )
        return await self._client._aget("/v1/queue/preview", params=params)

    async def aget_next_queue_slot(
        self, profile_id: str, *, queue_id: str | None = None
    ) -> dict[str, Any]:
        """Get next available slot (async)"""
        params = self._build_params(
            profile_id=profile_id,
            queue_id=queue_id,
        )
        return await self._client._aget("/v1/queue/next-slot", params=params)
