# Generated by smithplates HTTP codegen. Do not edit.

from __future__ import annotations

from datetime import datetime, timezone  # noqa: F401
from urllib.parse import quote

import httpx
from pydantic import Field  # noqa: F401

from generated.petstore.api.create_pet_input import CreatePetInput
from generated.petstore.api.create_pet_output import CreatePetOutput
from generated.petstore.api.get_pet_output import GetPetOutput
from generated.petstore.api.pet_location_redirect import PetLocationRedirect
from generated.petstore.api.pet_not_found import PetNotFound
from generated.petstore.api.petstore.client.client_response import parse_client_response
from generated.petstore.api.petstore.client.operation_bindings import OPERATION_HTTP_BINDINGS
from generated.petstore.api.update_pet_body import UpdatePetBody
from generated.petstore.api.update_pet_output import UpdatePetOutput
from generated.petstore.api.validation_error import ValidationError


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


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

    async def create_pet(
        self,
        create_pet_input: CreatePetInput,
    ) -> CreatePetOutput | ValidationError:
        """HTTP-facing petstore contract. Generated FastAPI routes call protocol implementations
        in `src/server` that delegate to generated `@sqlService` repositories."""
        headers: dict[str, str] | None = None

        request_url = f"{self._base_url}/pets"
        response = await self._client.request(
            "POST",
            request_url,
            headers=headers,
            json=create_pet_input.model_dump(mode="json", exclude_none=True),
        )
        return parse_client_response(
            response,
            OPERATION_HTTP_BINDINGS["create_pet"],
        )

    async def delete_pet(
        self,
        pet_id: str,
    ) -> PetNotFound | None:
        headers: dict[str, str] | None = None
        _encoded_pet_id = _encode_path_label(pet_id)
        request_url = f"{self._base_url}/pets/{_encoded_pet_id}"
        response = await self._client.request(
            "DELETE",
            request_url,
            headers=headers,
        )
        return parse_client_response(
            response,
            OPERATION_HTTP_BINDINGS["delete_pet"],
        )

    async def get_pet(
        self,
        pet_id: str,
    ) -> GetPetOutput | PetNotFound:
        headers: dict[str, str] | None = None
        _encoded_pet_id = _encode_path_label(pet_id)
        request_url = f"{self._base_url}/pets/{_encoded_pet_id}"
        response = await self._client.request(
            "GET",
            request_url,
            headers=headers,
        )
        return parse_client_response(
            response,
            OPERATION_HTTP_BINDINGS["get_pet"],
        )

    async def resolve_pet_location(
        self,
        pet_id: str,
    ) -> PetLocationRedirect | PetNotFound:
        headers: dict[str, str] | None = None
        _encoded_pet_id = _encode_path_label(pet_id)
        request_url = f"{self._base_url}/pets/{_encoded_pet_id}/location"
        response = await self._client.request(
            "GET",
            request_url,
            headers=headers,
        )
        return parse_client_response(
            response,
            OPERATION_HTTP_BINDINGS["resolve_pet_location"],
        )

    async def update_pet(
        self,
        pet_id: str,
        body: UpdatePetBody,
    ) -> UpdatePetOutput | PetNotFound | ValidationError:
        headers: dict[str, str] | None = None
        _encoded_pet_id = _encode_path_label(pet_id)
        request_url = f"{self._base_url}/pets/{_encoded_pet_id}"
        response = await self._client.request(
            "PUT",
            request_url,
            headers=headers,
            json=body.model_dump(mode="json", exclude_none=True),
        )
        return parse_client_response(
            response,
            OPERATION_HTTP_BINDINGS["update_pet"],
        )
