from typing import Any

import httpx

from peertube import errors
from peertube.api.shared_utils import build_response
from peertube.client import AuthenticatedClient, Client
from peertube.models.delete_api_v1_runners_runner_id_body import (
    DeleteApiV1RunnersRunnerIdBody,
)
from peertube.types import Response


def _get_kwargs(
    runner_id: int, *, body: DeleteApiV1RunnersRunnerIdBody
) -> dict[str, Any]:
    headers: dict[str, Any] = {}

    _kwargs: dict[str, Any] = {
        "method": "delete",
        "url": f"/api/v1/runners/{runner_id}",
    }
    _kwargs["json"] = body.to_dict()

    headers["Content-Type"] = "application/json"

    _kwargs["headers"] = headers
    return _kwargs


def _parse_response(
    *, client: AuthenticatedClient | Client, response: httpx.Response
) -> Any | None:
    if response.status_code == 204:
        return None
    if client.raise_on_unexpected_status:
        raise errors.UnexpectedStatus(response.status_code, response.content)
    else:
        return None


def _build_response(
    *, client: AuthenticatedClient | Client, response: httpx.Response
) -> Response[Any]:
    return build_response(client=client, response=response)


def sync_detailed(
    runner_id: int, *, client: AuthenticatedClient, body: DeleteApiV1RunnersRunnerIdBody
) -> Response[Any]:
    """Delete a runner


    Args:
        runner_id (int): Parameter for runner id.
        body (DeleteApiV1RunnersRunnerIdBody): Request body data.

    Raises:
        errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
        httpx.TimeoutException: If the request takes longer than Client.timeout.

    Returns:
        Response[Any]
    """

    kwargs = _get_kwargs(runner_id=runner_id, body=body)

    response = client.get_httpx_client().request(**kwargs)

    return _build_response(client=client, response=response)


def sync(
    runner_id: int, *, client: AuthenticatedClient, body: DeleteApiV1RunnersRunnerIdBody
) -> Any | None:
    """Delete a runner


    Raises:
        errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
        httpx.TimeoutException: If the request takes longer than Client.timeout.

    Returns:
        Any
    """

    return sync_detailed(runner_id=runner_id, client=client, body=body).parsed


async def asyncio_detailed(
    runner_id: int, *, client: AuthenticatedClient, body: DeleteApiV1RunnersRunnerIdBody
) -> Response[Any]:
    """Delete a runner


    Args:
        runner_id (int): Parameter for runner id.
        body (DeleteApiV1RunnersRunnerIdBody): Request body data.

    Raises:
        errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
        httpx.TimeoutException: If the request takes longer than Client.timeout.

    Returns:
        Response[Any]
    """

    kwargs = _get_kwargs(runner_id=runner_id, body=body)

    response = await client.get_async_httpx_client().request(**kwargs)

    return _build_response(client=client, response=response)
