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

from __future__ import annotations

from typing import List, Type, Optional, cast

import httpx

from ...._types import Body, Omit, Query, Headers, NotGiven, SequenceNotStr, omit, 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 ...._wrappers import ResultWrapper
from ...._base_client import make_request_options
from ....types.security_center.insights import type_get_params
from ....types.intel.attack_surface_report.issue_type import IssueType
from ....types.security_center.insights.type_get_response import TypeGetResponse
from ....types.intel.attack_surface_report.severity_query_param import SeverityQueryParam

__all__ = ["TypeResource", "AsyncTypeResource"]


class TypeResource(SyncAPIResource):
    @cached_property
    def with_raw_response(self) -> TypeResourceWithRawResponse:
        """
        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/cloudflare/cloudflare-python#accessing-raw-response-data-eg-headers
        """
        return TypeResourceWithRawResponse(self)

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

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

    def get(
        self,
        *,
        account_id: str | Omit = omit,
        zone_id: str | Omit = omit,
        dismissed: bool | Omit = omit,
        issue_class: SequenceNotStr[str] | Omit = omit,
        issue_class_neq: SequenceNotStr[str] | Omit = omit,
        issue_type: List[IssueType] | Omit = omit,
        issue_type_neq: List[IssueType] | Omit = omit,
        product: SequenceNotStr[str] | Omit = omit,
        product_neq: SequenceNotStr[str] | Omit = omit,
        severity: List[SeverityQueryParam] | Omit = omit,
        severity_neq: List[SeverityQueryParam] | Omit = omit,
        subject: SequenceNotStr[str] | Omit = omit,
        subject_neq: SequenceNotStr[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,
    ) -> Optional[TypeGetResponse]:
        """
        Retrieves Security Center insight counts aggregated by insight type.

        Args:
          account_id: The Account ID to use for this endpoint. Mutually exclusive with the Zone ID.

          zone_id: The Zone ID to use for this endpoint. Mutually exclusive with the Account ID.

          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 account_id and zone_id:
            raise ValueError("You cannot provide both account_id and zone_id")

        if account_id:
            account_or_zone = "accounts"
            account_or_zone_id = account_id
        else:
            if not zone_id:
                raise ValueError("You must provide either account_id or zone_id")

            account_or_zone = "zones"
            account_or_zone_id = zone_id
        return self._get(
            path_template(
                "/{account_or_zone}/{account_or_zone_id}/security-center/insights/type",
                account_or_zone=account_or_zone,
                account_or_zone_id=account_or_zone_id,
            ),
            options=make_request_options(
                extra_headers=extra_headers,
                extra_query=extra_query,
                extra_body=extra_body,
                timeout=timeout,
                query=maybe_transform(
                    {
                        "dismissed": dismissed,
                        "issue_class": issue_class,
                        "issue_class_neq": issue_class_neq,
                        "issue_type": issue_type,
                        "issue_type_neq": issue_type_neq,
                        "product": product,
                        "product_neq": product_neq,
                        "severity": severity,
                        "severity_neq": severity_neq,
                        "subject": subject,
                        "subject_neq": subject_neq,
                    },
                    type_get_params.TypeGetParams,
                ),
                post_parser=ResultWrapper[Optional[TypeGetResponse]]._unwrapper,
            ),
            cast_to=cast(Type[Optional[TypeGetResponse]], ResultWrapper[TypeGetResponse]),
        )


class AsyncTypeResource(AsyncAPIResource):
    @cached_property
    def with_raw_response(self) -> AsyncTypeResourceWithRawResponse:
        """
        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/cloudflare/cloudflare-python#accessing-raw-response-data-eg-headers
        """
        return AsyncTypeResourceWithRawResponse(self)

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

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

    async def get(
        self,
        *,
        account_id: str | Omit = omit,
        zone_id: str | Omit = omit,
        dismissed: bool | Omit = omit,
        issue_class: SequenceNotStr[str] | Omit = omit,
        issue_class_neq: SequenceNotStr[str] | Omit = omit,
        issue_type: List[IssueType] | Omit = omit,
        issue_type_neq: List[IssueType] | Omit = omit,
        product: SequenceNotStr[str] | Omit = omit,
        product_neq: SequenceNotStr[str] | Omit = omit,
        severity: List[SeverityQueryParam] | Omit = omit,
        severity_neq: List[SeverityQueryParam] | Omit = omit,
        subject: SequenceNotStr[str] | Omit = omit,
        subject_neq: SequenceNotStr[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,
    ) -> Optional[TypeGetResponse]:
        """
        Retrieves Security Center insight counts aggregated by insight type.

        Args:
          account_id: The Account ID to use for this endpoint. Mutually exclusive with the Zone ID.

          zone_id: The Zone ID to use for this endpoint. Mutually exclusive with the Account ID.

          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 account_id and zone_id:
            raise ValueError("You cannot provide both account_id and zone_id")

        if account_id:
            account_or_zone = "accounts"
            account_or_zone_id = account_id
        else:
            if not zone_id:
                raise ValueError("You must provide either account_id or zone_id")

            account_or_zone = "zones"
            account_or_zone_id = zone_id
        return await self._get(
            path_template(
                "/{account_or_zone}/{account_or_zone_id}/security-center/insights/type",
                account_or_zone=account_or_zone,
                account_or_zone_id=account_or_zone_id,
            ),
            options=make_request_options(
                extra_headers=extra_headers,
                extra_query=extra_query,
                extra_body=extra_body,
                timeout=timeout,
                query=await async_maybe_transform(
                    {
                        "dismissed": dismissed,
                        "issue_class": issue_class,
                        "issue_class_neq": issue_class_neq,
                        "issue_type": issue_type,
                        "issue_type_neq": issue_type_neq,
                        "product": product,
                        "product_neq": product_neq,
                        "severity": severity,
                        "severity_neq": severity_neq,
                        "subject": subject,
                        "subject_neq": subject_neq,
                    },
                    type_get_params.TypeGetParams,
                ),
                post_parser=ResultWrapper[Optional[TypeGetResponse]]._unwrapper,
            ),
            cast_to=cast(Type[Optional[TypeGetResponse]], ResultWrapper[TypeGetResponse]),
        )


class TypeResourceWithRawResponse:
    def __init__(self, type: TypeResource) -> None:
        self._type = type

        self.get = to_raw_response_wrapper(
            type.get,
        )


class AsyncTypeResourceWithRawResponse:
    def __init__(self, type: AsyncTypeResource) -> None:
        self._type = type

        self.get = async_to_raw_response_wrapper(
            type.get,
        )


class TypeResourceWithStreamingResponse:
    def __init__(self, type: TypeResource) -> None:
        self._type = type

        self.get = to_streamed_response_wrapper(
            type.get,
        )


class AsyncTypeResourceWithStreamingResponse:
    def __init__(self, type: AsyncTypeResource) -> None:
        self._type = type

        self.get = async_to_streamed_response_wrapper(
            type.get,
        )
