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

from __future__ import annotations

import httpx

from ..._types import Body, Query, Headers, NotGiven, not_given
from ..._utils import path_template, 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.personas import link_create_params
from ...types.personas.link_create_response import LinkCreateResponse
from ...types.personas.link_delete_response import LinkDeleteResponse

__all__ = ["LinkResource", "AsyncLinkResource"]


class LinkResource(SyncAPIResource):
    @cached_property
    def with_raw_response(self) -> LinkResourceWithRawResponse:
        """
        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/ElicitLabs/elicitlabs-python-sdk#accessing-raw-response-data-eg-headers
        """
        return LinkResourceWithRawResponse(self)

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

        For more information, see https://www.github.com/ElicitLabs/elicitlabs-python-sdk#with_streaming_response
        """
        return LinkResourceWithStreamingResponse(self)

    def create(
        self,
        persona_id: str,
        *,
        user_id: str,
        # 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,
    ) -> LinkCreateResponse:
        """
        Link a user to a persona by creating a personal clone of the template persona's
        knowledge graph. The clone has its own persona_id and diverges independently as
        new data is ingested.

            When the user later calls any endpoint with the *template* persona_id,
            the system transparently routes to the clone.

        Args:
          user_id: The user ID to link

          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
        """
        if not persona_id:
            raise ValueError(f"Expected a non-empty value for `persona_id` but received {persona_id!r}")
        return self._post(
            path_template("/v1/personas/{persona_id}/link", persona_id=persona_id),
            body=maybe_transform({"user_id": user_id}, link_create_params.LinkCreateParams),
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            cast_to=LinkCreateResponse,
        )

    def delete(
        self,
        user_id: str,
        *,
        persona_id: str,
        # 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,
    ) -> LinkDeleteResponse:
        """Remove a user's link to a persona.

        The user will no longer see the persona's
        memories.

        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
        """
        if not persona_id:
            raise ValueError(f"Expected a non-empty value for `persona_id` but received {persona_id!r}")
        if not user_id:
            raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}")
        return self._delete(
            path_template("/v1/personas/{persona_id}/link/{user_id}", persona_id=persona_id, user_id=user_id),
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            cast_to=LinkDeleteResponse,
        )


class AsyncLinkResource(AsyncAPIResource):
    @cached_property
    def with_raw_response(self) -> AsyncLinkResourceWithRawResponse:
        """
        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/ElicitLabs/elicitlabs-python-sdk#accessing-raw-response-data-eg-headers
        """
        return AsyncLinkResourceWithRawResponse(self)

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

        For more information, see https://www.github.com/ElicitLabs/elicitlabs-python-sdk#with_streaming_response
        """
        return AsyncLinkResourceWithStreamingResponse(self)

    async def create(
        self,
        persona_id: str,
        *,
        user_id: str,
        # 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,
    ) -> LinkCreateResponse:
        """
        Link a user to a persona by creating a personal clone of the template persona's
        knowledge graph. The clone has its own persona_id and diverges independently as
        new data is ingested.

            When the user later calls any endpoint with the *template* persona_id,
            the system transparently routes to the clone.

        Args:
          user_id: The user ID to link

          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
        """
        if not persona_id:
            raise ValueError(f"Expected a non-empty value for `persona_id` but received {persona_id!r}")
        return await self._post(
            path_template("/v1/personas/{persona_id}/link", persona_id=persona_id),
            body=await async_maybe_transform({"user_id": user_id}, link_create_params.LinkCreateParams),
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            cast_to=LinkCreateResponse,
        )

    async def delete(
        self,
        user_id: str,
        *,
        persona_id: str,
        # 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,
    ) -> LinkDeleteResponse:
        """Remove a user's link to a persona.

        The user will no longer see the persona's
        memories.

        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
        """
        if not persona_id:
            raise ValueError(f"Expected a non-empty value for `persona_id` but received {persona_id!r}")
        if not user_id:
            raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}")
        return await self._delete(
            path_template("/v1/personas/{persona_id}/link/{user_id}", persona_id=persona_id, user_id=user_id),
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            cast_to=LinkDeleteResponse,
        )


class LinkResourceWithRawResponse:
    def __init__(self, link: LinkResource) -> None:
        self._link = link

        self.create = to_raw_response_wrapper(
            link.create,
        )
        self.delete = to_raw_response_wrapper(
            link.delete,
        )


class AsyncLinkResourceWithRawResponse:
    def __init__(self, link: AsyncLinkResource) -> None:
        self._link = link

        self.create = async_to_raw_response_wrapper(
            link.create,
        )
        self.delete = async_to_raw_response_wrapper(
            link.delete,
        )


class LinkResourceWithStreamingResponse:
    def __init__(self, link: LinkResource) -> None:
        self._link = link

        self.create = to_streamed_response_wrapper(
            link.create,
        )
        self.delete = to_streamed_response_wrapper(
            link.delete,
        )


class AsyncLinkResourceWithStreamingResponse:
    def __init__(self, link: AsyncLinkResource) -> None:
        self._link = link

        self.create = async_to_streamed_response_wrapper(
            link.create,
        )
        self.delete = async_to_streamed_response_wrapper(
            link.delete,
        )
