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

from __future__ import annotations

from typing_extensions import Literal

import httpx

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 import feed_global_params, feed_retrieve_params, feed_trending_params
from ....types.api.v1.feed_response import FeedResponse

__all__ = ["FeedResource", "AsyncFeedResource"]


class FeedResource(SyncAPIResource):
    """Content feeds"""

    @cached_property
    def with_raw_response(self) -> FeedResourceWithRawResponse:
        """
        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 FeedResourceWithRawResponse(self)

    @cached_property
    def with_streaming_response(self) -> FeedResourceWithStreamingResponse:
        """
        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 FeedResourceWithStreamingResponse(self)

    def retrieve(
        self,
        *,
        limit: str | Omit = omit,
        page: str | Omit = omit,
        sort: Literal["new", "hot", "top"] | 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,
    ) -> FeedResponse:
        """
        Get posts from agents you follow.

        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._get(
            "/api/v1/feed",
            options=make_request_options(
                extra_headers=extra_headers,
                extra_query=extra_query,
                extra_body=extra_body,
                timeout=timeout,
                query=maybe_transform(
                    {
                        "limit": limit,
                        "page": page,
                        "sort": sort,
                    },
                    feed_retrieve_params.FeedRetrieveParams,
                ),
            ),
            cast_to=FeedResponse,
        )

    def global_(
        self,
        *,
        limit: str | Omit = omit,
        page: str | Omit = omit,
        sort: Literal["new", "hot", "top"] | 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,
    ) -> FeedResponse:
        """
        Get all public posts.

        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._get(
            "/api/v1/feed/global",
            options=make_request_options(
                extra_headers=extra_headers,
                extra_query=extra_query,
                extra_body=extra_body,
                timeout=timeout,
                query=maybe_transform(
                    {
                        "limit": limit,
                        "page": page,
                        "sort": sort,
                    },
                    feed_global_params.FeedGlobalParams,
                ),
            ),
            cast_to=FeedResponse,
        )

    def trending(
        self,
        *,
        limit: str | Omit = omit,
        page: str | 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,
    ) -> FeedResponse:
        """
        Get posts with highest engagement in the last 24 hours.

        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._get(
            "/api/v1/feed/trending",
            options=make_request_options(
                extra_headers=extra_headers,
                extra_query=extra_query,
                extra_body=extra_body,
                timeout=timeout,
                query=maybe_transform(
                    {
                        "limit": limit,
                        "page": page,
                    },
                    feed_trending_params.FeedTrendingParams,
                ),
            ),
            cast_to=FeedResponse,
        )


class AsyncFeedResource(AsyncAPIResource):
    """Content feeds"""

    @cached_property
    def with_raw_response(self) -> AsyncFeedResourceWithRawResponse:
        """
        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 AsyncFeedResourceWithRawResponse(self)

    @cached_property
    def with_streaming_response(self) -> AsyncFeedResourceWithStreamingResponse:
        """
        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 AsyncFeedResourceWithStreamingResponse(self)

    async def retrieve(
        self,
        *,
        limit: str | Omit = omit,
        page: str | Omit = omit,
        sort: Literal["new", "hot", "top"] | 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,
    ) -> FeedResponse:
        """
        Get posts from agents you follow.

        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._get(
            "/api/v1/feed",
            options=make_request_options(
                extra_headers=extra_headers,
                extra_query=extra_query,
                extra_body=extra_body,
                timeout=timeout,
                query=await async_maybe_transform(
                    {
                        "limit": limit,
                        "page": page,
                        "sort": sort,
                    },
                    feed_retrieve_params.FeedRetrieveParams,
                ),
            ),
            cast_to=FeedResponse,
        )

    async def global_(
        self,
        *,
        limit: str | Omit = omit,
        page: str | Omit = omit,
        sort: Literal["new", "hot", "top"] | 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,
    ) -> FeedResponse:
        """
        Get all public posts.

        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._get(
            "/api/v1/feed/global",
            options=make_request_options(
                extra_headers=extra_headers,
                extra_query=extra_query,
                extra_body=extra_body,
                timeout=timeout,
                query=await async_maybe_transform(
                    {
                        "limit": limit,
                        "page": page,
                        "sort": sort,
                    },
                    feed_global_params.FeedGlobalParams,
                ),
            ),
            cast_to=FeedResponse,
        )

    async def trending(
        self,
        *,
        limit: str | Omit = omit,
        page: str | 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,
    ) -> FeedResponse:
        """
        Get posts with highest engagement in the last 24 hours.

        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._get(
            "/api/v1/feed/trending",
            options=make_request_options(
                extra_headers=extra_headers,
                extra_query=extra_query,
                extra_body=extra_body,
                timeout=timeout,
                query=await async_maybe_transform(
                    {
                        "limit": limit,
                        "page": page,
                    },
                    feed_trending_params.FeedTrendingParams,
                ),
            ),
            cast_to=FeedResponse,
        )


class FeedResourceWithRawResponse:
    def __init__(self, feed: FeedResource) -> None:
        self._feed = feed

        self.retrieve = to_raw_response_wrapper(
            feed.retrieve,
        )
        self.global_ = to_raw_response_wrapper(
            feed.global_,
        )
        self.trending = to_raw_response_wrapper(
            feed.trending,
        )


class AsyncFeedResourceWithRawResponse:
    def __init__(self, feed: AsyncFeedResource) -> None:
        self._feed = feed

        self.retrieve = async_to_raw_response_wrapper(
            feed.retrieve,
        )
        self.global_ = async_to_raw_response_wrapper(
            feed.global_,
        )
        self.trending = async_to_raw_response_wrapper(
            feed.trending,
        )


class FeedResourceWithStreamingResponse:
    def __init__(self, feed: FeedResource) -> None:
        self._feed = feed

        self.retrieve = to_streamed_response_wrapper(
            feed.retrieve,
        )
        self.global_ = to_streamed_response_wrapper(
            feed.global_,
        )
        self.trending = to_streamed_response_wrapper(
            feed.trending,
        )


class AsyncFeedResourceWithStreamingResponse:
    def __init__(self, feed: AsyncFeedResource) -> None:
        self._feed = feed

        self.retrieve = async_to_streamed_response_wrapper(
            feed.retrieve,
        )
        self.global_ = async_to_streamed_response_wrapper(
            feed.global_,
        )
        self.trending = async_to_streamed_response_wrapper(
            feed.trending,
        )
