# Generated by smithplates HTTP codegen. Do not edit.

from __future__ import annotations

from urllib.parse import quote

import httpx
from generated.example.conflict import Conflict
from generated.example.item_details import ItemDetails
from generated.example.service_unavailable import ServiceUnavailable
from generated.example.shelf_item_output import ShelfItemOutput
from generated.example.shelf_sku_output import ShelfSkuOutput
from generated.warehouse_api_client.warehouse_api.client.client_response import parse_client_response
from generated.warehouse_api_client.warehouse_api.client.operation_bindings import OPERATION_HTTP_BINDINGS
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 WarehouseApiClient:
    def __init__(self, client: httpx.AsyncClient, base_url: str) -> None:
        self._client = client
        self._base_url = base_url.rstrip("/")

    async def assign_shelf_sku(
        self,
        request_id: str | None,
        shelf_id: str,
        sku: str,
    ) -> ShelfSkuOutput | ServiceUnavailable:
        """POST with @httpHeader, one @httpLabel, and a primitive payload body member."""
        headers: dict[str, str] = {}
        if request_id is not None:
            headers["X-Request-Id"] = str(request_id)
        _encoded_shelf_id = _encode_path_label(shelf_id)
        request_url = f"{self._base_url}/shelves/{_encoded_shelf_id}/skus"
        response = await self._client.request(
            "POST",
            request_url,
            headers=headers,
            json=sku,
        )
        return parse_client_response(
            response,
            OPERATION_HTTP_BINDINGS["assign_shelf_sku"],
        )

    async def create_shelf_item(
        self,
        idempotency_key: str | None,
        warehouse_id: str,
        shelf_id: str,
        details: ItemDetails,
    ) -> ShelfItemOutput | Conflict | ServiceUnavailable:
        """POST with @httpHeader, @httpLabel path labels, and a nested structure @httpPayload body."""
        headers: dict[str, str] = {}
        if idempotency_key is not None:
            headers["X-Idempotency-Key"] = str(idempotency_key)
        _encoded_warehouse_id = _encode_path_label(warehouse_id)
        _encoded_shelf_id = _encode_path_label(shelf_id)
        request_url = f"{self._base_url}/warehouses/{_encoded_warehouse_id}/shelves/{_encoded_shelf_id}/items"
        response = await self._client.request(
            "POST",
            request_url,
            headers=headers,
            json=details.model_dump(mode="json", exclude_none=True),
        )
        return parse_client_response(
            response,
            OPERATION_HTTP_BINDINGS["create_shelf_item"],
        )
