# Generated by smithplates HTTP codegen. Do not edit.

from __future__ import annotations

from urllib.parse import quote

import httpx2
from generated.example.widget_api.client.client_response import parse_client_response
from generated.example.widget_api.client.operation_bindings import OPERATION_HTTP_BINDINGS
from generated.example.widget_output import WidgetOutput
from pydantic import Field  # noqa: F401


def _encode_path_label(value: object, *, greedy: bool = False) -> str:
    return quote(str(value), safe="/" if greedy else "")


class WidgetsApiClient:
    def __init__(self, client: httpx2.AsyncClient, base_url: str) -> None:
        self._client = client
        self._base_url = base_url.rstrip("/")

    async def get_widget(
        self,
        widget_id: str,
    ) -> WidgetOutput:
        headers: dict[str, str] | None = None
        _encoded_widget_id = _encode_path_label(widget_id)
        request_url = f"{self._base_url}/widgets/{_encoded_widget_id}"
        response = await self._client.request(
            "GET",
            request_url,
            headers=headers,
        )
        return parse_client_response(
            response,
            OPERATION_HTTP_BINDINGS["get_widget"],
        )
