from http import HTTPStatus
from typing import Any
from urllib.parse import quote

import httpx

from ... import errors
from ...client import AuthenticatedClient, Client
from ...models.get_contacts_contact_response_200 import GetContactsContactResponse200
from ...models.get_contacts_contact_response_400 import GetContactsContactResponse400
from ...models.get_contacts_contact_response_401 import GetContactsContactResponse401
from ...models.get_contacts_contact_response_404 import GetContactsContactResponse404
from ...models.get_contacts_contact_response_500 import GetContactsContactResponse500
from ...types import UNSET, Response, Unset


def _get_kwargs(
    contact: str,
    *,
    full: str | Unset = UNSET,
    activity: str | Unset = UNSET,
) -> dict[str, Any]:

    params: dict[str, Any] = {}

    params["full"] = full

    params["activity"] = activity

    params = {k: v for k, v in params.items() if v is not UNSET and v is not None}

    _kwargs: dict[str, Any] = {
        "method": "get",
        "url": "/contacts/{contact}".format(
            contact=quote(str(contact), safe=""),
        ),
        "params": params,
    }

    return _kwargs


def _parse_response(
    *, client: AuthenticatedClient | Client, response: httpx.Response
) -> (
    GetContactsContactResponse200
    | GetContactsContactResponse400
    | GetContactsContactResponse401
    | GetContactsContactResponse404
    | GetContactsContactResponse500
    | None
):
    if response.status_code == 200:
        response_200 = GetContactsContactResponse200.from_dict(response.json())

        return response_200

    if response.status_code == 400:
        response_400 = GetContactsContactResponse400.from_dict(response.json())

        return response_400

    if response.status_code == 401:
        response_401 = GetContactsContactResponse401.from_dict(response.json())

        return response_401

    if response.status_code == 404:
        response_404 = GetContactsContactResponse404.from_dict(response.json())

        return response_404

    if response.status_code == 500:
        response_500 = GetContactsContactResponse500.from_dict(response.json())

        return response_500

    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[
    GetContactsContactResponse200
    | GetContactsContactResponse400
    | GetContactsContactResponse401
    | GetContactsContactResponse404
    | GetContactsContactResponse500
]:
    return Response(
        status_code=HTTPStatus(response.status_code),
        content=response.content,
        headers=response.headers,
        parsed=_parse_response(client=client, response=response),
    )


def sync_detailed(
    contact: str,
    *,
    client: AuthenticatedClient,
    full: str | Unset = UNSET,
    activity: str | Unset = UNSET,
) -> Response[
    GetContactsContactResponse200
    | GetContactsContactResponse400
    | GetContactsContactResponse401
    | GetContactsContactResponse404
    | GetContactsContactResponse500
]:
    """Get contact

     Get contact details. Use ?full=true to include client associations, plans, deals, and access
    information. Use ?activity=true to include recent email activity

    Args:
        contact (str):
        full (str | Unset):
        activity (str | Unset):

    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[GetContactsContactResponse200 | GetContactsContactResponse400 | GetContactsContactResponse401 | GetContactsContactResponse404 | GetContactsContactResponse500]
    """

    kwargs = _get_kwargs(
        contact=contact,
        full=full,
        activity=activity,
    )

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

    return _build_response(client=client, response=response)


def sync(
    contact: str,
    *,
    client: AuthenticatedClient,
    full: str | Unset = UNSET,
    activity: str | Unset = UNSET,
) -> (
    GetContactsContactResponse200
    | GetContactsContactResponse400
    | GetContactsContactResponse401
    | GetContactsContactResponse404
    | GetContactsContactResponse500
    | None
):
    """Get contact

     Get contact details. Use ?full=true to include client associations, plans, deals, and access
    information. Use ?activity=true to include recent email activity

    Args:
        contact (str):
        full (str | Unset):
        activity (str | Unset):

    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:
        GetContactsContactResponse200 | GetContactsContactResponse400 | GetContactsContactResponse401 | GetContactsContactResponse404 | GetContactsContactResponse500
    """

    return sync_detailed(
        contact=contact,
        client=client,
        full=full,
        activity=activity,
    ).parsed


async def asyncio_detailed(
    contact: str,
    *,
    client: AuthenticatedClient,
    full: str | Unset = UNSET,
    activity: str | Unset = UNSET,
) -> Response[
    GetContactsContactResponse200
    | GetContactsContactResponse400
    | GetContactsContactResponse401
    | GetContactsContactResponse404
    | GetContactsContactResponse500
]:
    """Get contact

     Get contact details. Use ?full=true to include client associations, plans, deals, and access
    information. Use ?activity=true to include recent email activity

    Args:
        contact (str):
        full (str | Unset):
        activity (str | Unset):

    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[GetContactsContactResponse200 | GetContactsContactResponse400 | GetContactsContactResponse401 | GetContactsContactResponse404 | GetContactsContactResponse500]
    """

    kwargs = _get_kwargs(
        contact=contact,
        full=full,
        activity=activity,
    )

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

    return _build_response(client=client, response=response)


async def asyncio(
    contact: str,
    *,
    client: AuthenticatedClient,
    full: str | Unset = UNSET,
    activity: str | Unset = UNSET,
) -> (
    GetContactsContactResponse200
    | GetContactsContactResponse400
    | GetContactsContactResponse401
    | GetContactsContactResponse404
    | GetContactsContactResponse500
    | None
):
    """Get contact

     Get contact details. Use ?full=true to include client associations, plans, deals, and access
    information. Use ?activity=true to include recent email activity

    Args:
        contact (str):
        full (str | Unset):
        activity (str | Unset):

    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:
        GetContactsContactResponse200 | GetContactsContactResponse400 | GetContactsContactResponse401 | GetContactsContactResponse404 | GetContactsContactResponse500
    """

    return (
        await asyncio_detailed(
            contact=contact,
            client=client,
            full=full,
            activity=activity,
        )
    ).parsed
