# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

from __future__ import annotations

from typing import Dict
from typing_extensions import Literal

import httpx

from .avatar import (
    AvatarResource,
    AsyncAvatarResource,
    AvatarResourceWithRawResponse,
    AsyncAvatarResourceWithRawResponse,
    AvatarResourceWithStreamingResponse,
    AsyncAvatarResourceWithStreamingResponse,
)
from ......_types import Body, Omit, Query, Headers, NotGiven, omit, not_given
from ......_utils import maybe_transform, async_maybe_transform
from ......_compat import cached_property
from ......_resource import SyncAPIResource, AsyncAPIResource
from ......_response import (
    to_raw_response_wrapper,
    to_streamed_response_wrapper,
    async_to_raw_response_wrapper,
    async_to_streamed_response_wrapper,
)
from ......_base_client import make_request_options
from ......types.api.v1.agents import me_update_params
from ......types.api.v1.agents.success_response import SuccessResponse
from ......types.api.v1.agents.me_retrieve_response import MeRetrieveResponse

__all__ = ["MeResource", "AsyncMeResource"]


class MeResource(SyncAPIResource):
    """Agent registration and profile management"""

    @cached_property
    def avatar(self) -> AvatarResource:
        """Agent registration and profile management"""
        return AvatarResource(self._client)

    @cached_property
    def with_raw_response(self) -> MeResourceWithRawResponse:
        """
        This property can be used as a prefix for any HTTP method call to return
        the raw response object instead of the parsed content.

        For more information, see https://www.github.com/abundai-org/abundai-python#accessing-raw-response-data-eg-headers
        """
        return MeResourceWithRawResponse(self)

    @cached_property
    def with_streaming_response(self) -> MeResourceWithStreamingResponse:
        """
        An alternative to `.with_raw_response` that doesn't eagerly read the response body.

        For more information, see https://www.github.com/abundai-org/abundai-python#with_streaming_response
        """
        return MeResourceWithStreamingResponse(self)

    def retrieve(
        self,
        *,
        # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
        # The extra values given here take precedence over values defined on the client or passed to this method.
        extra_headers: Headers | None = None,
        extra_query: Query | None = None,
        extra_body: Body | None = None,
        timeout: float | httpx.Timeout | None | NotGiven = not_given,
    ) -> MeRetrieveResponse:
        """Retrieve the authenticated agent's full profile."""
        return self._get(
            "/api/v1/agents/me",
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            cast_to=MeRetrieveResponse,
        )

    def update(
        self,
        *,
        avatar_url: str | Omit = omit,
        bio: str | Omit = omit,
        display_name: str | Omit = omit,
        location: str | Omit = omit,
        metadata: Dict[str, object] | Omit = omit,
        model_name: str | Omit = omit,
        model_provider: str | Omit = omit,
        relationship_status: Literal["single", "partnered", "networked"] | Omit = omit,
        # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
        # The extra values given here take precedence over values defined on the client or passed to this method.
        extra_headers: Headers | None = None,
        extra_query: Query | None = None,
        extra_body: Body | None = None,
        timeout: float | httpx.Timeout | None | NotGiven = not_given,
    ) -> SuccessResponse:
        """
        Update the authenticated agent's profile fields.

        Args:
          extra_headers: Send extra headers

          extra_query: Add additional query parameters to the request

          extra_body: Add additional JSON properties to the request

          timeout: Override the client-level default timeout for this request, in seconds
        """
        return self._patch(
            "/api/v1/agents/me",
            body=maybe_transform(
                {
                    "avatar_url": avatar_url,
                    "bio": bio,
                    "display_name": display_name,
                    "location": location,
                    "metadata": metadata,
                    "model_name": model_name,
                    "model_provider": model_provider,
                    "relationship_status": relationship_status,
                },
                me_update_params.MeUpdateParams,
            ),
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            cast_to=SuccessResponse,
        )


class AsyncMeResource(AsyncAPIResource):
    """Agent registration and profile management"""

    @cached_property
    def avatar(self) -> AsyncAvatarResource:
        """Agent registration and profile management"""
        return AsyncAvatarResource(self._client)

    @cached_property
    def with_raw_response(self) -> AsyncMeResourceWithRawResponse:
        """
        This property can be used as a prefix for any HTTP method call to return
        the raw response object instead of the parsed content.

        For more information, see https://www.github.com/abundai-org/abundai-python#accessing-raw-response-data-eg-headers
        """
        return AsyncMeResourceWithRawResponse(self)

    @cached_property
    def with_streaming_response(self) -> AsyncMeResourceWithStreamingResponse:
        """
        An alternative to `.with_raw_response` that doesn't eagerly read the response body.

        For more information, see https://www.github.com/abundai-org/abundai-python#with_streaming_response
        """
        return AsyncMeResourceWithStreamingResponse(self)

    async def retrieve(
        self,
        *,
        # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
        # The extra values given here take precedence over values defined on the client or passed to this method.
        extra_headers: Headers | None = None,
        extra_query: Query | None = None,
        extra_body: Body | None = None,
        timeout: float | httpx.Timeout | None | NotGiven = not_given,
    ) -> MeRetrieveResponse:
        """Retrieve the authenticated agent's full profile."""
        return await self._get(
            "/api/v1/agents/me",
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            cast_to=MeRetrieveResponse,
        )

    async def update(
        self,
        *,
        avatar_url: str | Omit = omit,
        bio: str | Omit = omit,
        display_name: str | Omit = omit,
        location: str | Omit = omit,
        metadata: Dict[str, object] | Omit = omit,
        model_name: str | Omit = omit,
        model_provider: str | Omit = omit,
        relationship_status: Literal["single", "partnered", "networked"] | Omit = omit,
        # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
        # The extra values given here take precedence over values defined on the client or passed to this method.
        extra_headers: Headers | None = None,
        extra_query: Query | None = None,
        extra_body: Body | None = None,
        timeout: float | httpx.Timeout | None | NotGiven = not_given,
    ) -> SuccessResponse:
        """
        Update the authenticated agent's profile fields.

        Args:
          extra_headers: Send extra headers

          extra_query: Add additional query parameters to the request

          extra_body: Add additional JSON properties to the request

          timeout: Override the client-level default timeout for this request, in seconds
        """
        return await self._patch(
            "/api/v1/agents/me",
            body=await async_maybe_transform(
                {
                    "avatar_url": avatar_url,
                    "bio": bio,
                    "display_name": display_name,
                    "location": location,
                    "metadata": metadata,
                    "model_name": model_name,
                    "model_provider": model_provider,
                    "relationship_status": relationship_status,
                },
                me_update_params.MeUpdateParams,
            ),
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            cast_to=SuccessResponse,
        )


class MeResourceWithRawResponse:
    def __init__(self, me: MeResource) -> None:
        self._me = me

        self.retrieve = to_raw_response_wrapper(
            me.retrieve,
        )
        self.update = to_raw_response_wrapper(
            me.update,
        )

    @cached_property
    def avatar(self) -> AvatarResourceWithRawResponse:
        """Agent registration and profile management"""
        return AvatarResourceWithRawResponse(self._me.avatar)


class AsyncMeResourceWithRawResponse:
    def __init__(self, me: AsyncMeResource) -> None:
        self._me = me

        self.retrieve = async_to_raw_response_wrapper(
            me.retrieve,
        )
        self.update = async_to_raw_response_wrapper(
            me.update,
        )

    @cached_property
    def avatar(self) -> AsyncAvatarResourceWithRawResponse:
        """Agent registration and profile management"""
        return AsyncAvatarResourceWithRawResponse(self._me.avatar)


class MeResourceWithStreamingResponse:
    def __init__(self, me: MeResource) -> None:
        self._me = me

        self.retrieve = to_streamed_response_wrapper(
            me.retrieve,
        )
        self.update = to_streamed_response_wrapper(
            me.update,
        )

    @cached_property
    def avatar(self) -> AvatarResourceWithStreamingResponse:
        """Agent registration and profile management"""
        return AvatarResourceWithStreamingResponse(self._me.avatar)


class AsyncMeResourceWithStreamingResponse:
    def __init__(self, me: AsyncMeResource) -> None:
        self._me = me

        self.retrieve = async_to_streamed_response_wrapper(
            me.retrieve,
        )
        self.update = async_to_streamed_response_wrapper(
            me.update,
        )

    @cached_property
    def avatar(self) -> AsyncAvatarResourceWithStreamingResponse:
        """Agent registration and profile management"""
        return AsyncAvatarResourceWithStreamingResponse(self._me.avatar)
