"""Remote command operations (lock, unlock, horn, lights, hazard, find)."""

from __future__ import annotations

from typing import Any

from tyta.core.client import ToyotaClient

# ---------------------------------------------------------------------------
# Endpoint constants
# ---------------------------------------------------------------------------

VEHICLE_COMMAND_ENDPOINT = "/v1/global/remote/command"

# ---------------------------------------------------------------------------
# Command constants
# ---------------------------------------------------------------------------

CMD_DOOR_LOCK = "door-lock"
CMD_DOOR_UNLOCK = "door-unlock"
CMD_SOUND_HORN = "sound-horn"
CMD_HEADLIGHT_ON = "headlight-on"
CMD_HEADLIGHT_OFF = "headlight-off"
CMD_HAZARD_ON = "hazard-on"
CMD_HAZARD_OFF = "hazard-off"
CMD_FIND_VEHICLE = "find-vehicle"

# ---------------------------------------------------------------------------
# Public API
# ---------------------------------------------------------------------------


async def send_command(
    client: ToyotaClient,
    vin: str,
    command: str,
    beep_count: int | None = None,
) -> dict[str, Any]:
    """Send a remote command to a vehicle.

    Args:
        client: Authenticated ToyotaClient instance.
        vin: Vehicle Identification Number.
        command: Command string (e.g. "door-lock", "sound-horn").
        beep_count: Optional beep count for commands that support it.

    Returns:
        Raw API response dict.

    Raises:
        ToyotaApiError: If the API returns a non-2xx response.

    """
    body: dict[str, Any] = {"command": command}
    if beep_count is not None:
        body["beepCount"] = beep_count
    return await client.post(VEHICLE_COMMAND_ENDPOINT, vin=vin, body=body)
