"""Commands / polling endpoint (write operations)."""

from __future__ import annotations

from typing import Any, Dict, List, Union

from sd_api.client.base import BaseClient


class CommandsMixin:
    """POST endpoints for sending commands and ticks."""

    def __init__(self, base: BaseClient) -> None:
        self._base = base

    def send_tick(
        self,
        tick: Union[Dict[str, Any], List[Dict[str, Any]]],
    ) -> None:
        """POST /api/tick — submit one or more ticks (fire-and-forget).

        Does not wait for a response body (204 No Content).
        """
        if isinstance(tick, dict):
            tick = [tick]
        self._base.post("/api/tick", json=tick)

    def send_tick_ren(self, ticks: List[Dict[str, Any]]) -> Dict[str, Any]:
        """POST /api/tick-ren — submit ticks with a count response."""
        return self._base.post("/api/tick-ren", json=ticks)

    def send_tick_hist(self, ticks: List[Dict[str, Any]]) -> Dict[str, Any]:
        """POST /api/tick-hist — submit historical tick batch."""
        return self._base.post("/api/tick-hist", json=ticks)
