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

from __future__ import annotations

from typing import List, Optional

import httpx

from .type import (
    TypeResource,
    AsyncTypeResource,
    TypeResourceWithRawResponse,
    AsyncTypeResourceWithRawResponse,
    TypeResourceWithStreamingResponse,
    AsyncTypeResourceWithStreamingResponse,
)
from .class_ import (
    ClassResource,
    AsyncClassResource,
    ClassResourceWithRawResponse,
    AsyncClassResourceWithRawResponse,
    ClassResourceWithStreamingResponse,
    AsyncClassResourceWithStreamingResponse,
)
from .context import (
    ContextResource,
    AsyncContextResource,
    ContextResourceWithRawResponse,
    AsyncContextResourceWithRawResponse,
    ContextResourceWithStreamingResponse,
    AsyncContextResourceWithStreamingResponse,
)
from .severity import (
    SeverityResource,
    AsyncSeverityResource,
    SeverityResourceWithRawResponse,
    AsyncSeverityResourceWithRawResponse,
    SeverityResourceWithStreamingResponse,
    AsyncSeverityResourceWithStreamingResponse,
)
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 .audit_logs import (
    AuditLogsResource,
    AsyncAuditLogsResource,
    AuditLogsResourceWithRawResponse,
    AsyncAuditLogsResourceWithRawResponse,
    AuditLogsResourceWithStreamingResponse,
    AsyncAuditLogsResourceWithStreamingResponse,
)
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 ....pagination import SyncV4PagePagination, AsyncV4PagePagination
from .classification import (
    ClassificationResource,
    AsyncClassificationResource,
    ClassificationResourceWithRawResponse,
    AsyncClassificationResourceWithRawResponse,
    ClassificationResourceWithStreamingResponse,
    AsyncClassificationResourceWithStreamingResponse,
)
from ...._base_client import AsyncPaginator, make_request_options
from ....types.security_center import insight_list_params, insight_dismiss_params
from ....types.security_center.insight_list_response import InsightListResponse
from ....types.intel.attack_surface_report.issue_type import IssueType
from ....types.security_center.insight_dismiss_response import InsightDismissResponse
from ....types.intel.attack_surface_report.severity_query_param import SeverityQueryParam

__all__ = ["InsightsResource", "AsyncInsightsResource"]


class InsightsResource(SyncAPIResource):
    @cached_property
    def class_(self) -> ClassResource:
        return ClassResource(self._client)

    @cached_property
    def severity(self) -> SeverityResource:
        return SeverityResource(self._client)

    @cached_property
    def type(self) -> TypeResource:
        return TypeResource(self._client)

    @cached_property
    def audit_logs(self) -> AuditLogsResource:
        return AuditLogsResource(self._client)

    @cached_property
    def classification(self) -> ClassificationResource:
        return ClassificationResource(self._client)

    @cached_property
    def context(self) -> ContextResource:
        return ContextResource(self._client)

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

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

    def list(
        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,
        page: int | Omit = omit,
        per_page: int | 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,
    ) -> SyncV4PagePagination[Optional[InsightListResponse]]:
        """
        Lists all Security Center insights for the account or zone, showing security
        findings and recommendations.

        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.

          page: Specifies the current page within paginated list of results.

          per_page: Sets the number of results per page of results.

          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_api_list(
            path_template(
                "/{account_or_zone}/{account_or_zone_id}/security-center/insights",
                account_or_zone=account_or_zone,
                account_or_zone_id=account_or_zone_id,
            ),
            page=SyncV4PagePagination[Optional[InsightListResponse]],
            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,
                        "page": page,
                        "per_page": per_page,
                        "product": product,
                        "product_neq": product_neq,
                        "severity": severity,
                        "severity_neq": severity_neq,
                        "subject": subject,
                        "subject_neq": subject_neq,
                    },
                    insight_list_params.InsightListParams,
                ),
            ),
            model=InsightListResponse,
        )

    def dismiss(
        self,
        issue_id: str,
        *,
        account_id: str | Omit = omit,
        zone_id: str | Omit = omit,
        dismiss: bool | 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,
    ) -> InsightDismissResponse:
        """
        Archives a Security Center insight for an account or zone, removing it from the
        active insights list while preserving historical data.

        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 not issue_id:
            raise ValueError(f"Expected a non-empty value for `issue_id` but received {issue_id!r}")
        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._put(
            path_template(
                "/{account_or_zone}/{account_or_zone_id}/security-center/insights/{issue_id}/dismiss",
                issue_id=issue_id,
                account_or_zone=account_or_zone,
                account_or_zone_id=account_or_zone_id,
            ),
            body=maybe_transform({"dismiss": dismiss}, insight_dismiss_params.InsightDismissParams),
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            cast_to=InsightDismissResponse,
        )


class AsyncInsightsResource(AsyncAPIResource):
    @cached_property
    def class_(self) -> AsyncClassResource:
        return AsyncClassResource(self._client)

    @cached_property
    def severity(self) -> AsyncSeverityResource:
        return AsyncSeverityResource(self._client)

    @cached_property
    def type(self) -> AsyncTypeResource:
        return AsyncTypeResource(self._client)

    @cached_property
    def audit_logs(self) -> AsyncAuditLogsResource:
        return AsyncAuditLogsResource(self._client)

    @cached_property
    def classification(self) -> AsyncClassificationResource:
        return AsyncClassificationResource(self._client)

    @cached_property
    def context(self) -> AsyncContextResource:
        return AsyncContextResource(self._client)

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

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

    def list(
        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,
        page: int | Omit = omit,
        per_page: int | 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,
    ) -> AsyncPaginator[Optional[InsightListResponse], AsyncV4PagePagination[Optional[InsightListResponse]]]:
        """
        Lists all Security Center insights for the account or zone, showing security
        findings and recommendations.

        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.

          page: Specifies the current page within paginated list of results.

          per_page: Sets the number of results per page of results.

          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_api_list(
            path_template(
                "/{account_or_zone}/{account_or_zone_id}/security-center/insights",
                account_or_zone=account_or_zone,
                account_or_zone_id=account_or_zone_id,
            ),
            page=AsyncV4PagePagination[Optional[InsightListResponse]],
            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,
                        "page": page,
                        "per_page": per_page,
                        "product": product,
                        "product_neq": product_neq,
                        "severity": severity,
                        "severity_neq": severity_neq,
                        "subject": subject,
                        "subject_neq": subject_neq,
                    },
                    insight_list_params.InsightListParams,
                ),
            ),
            model=InsightListResponse,
        )

    async def dismiss(
        self,
        issue_id: str,
        *,
        account_id: str | Omit = omit,
        zone_id: str | Omit = omit,
        dismiss: bool | 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,
    ) -> InsightDismissResponse:
        """
        Archives a Security Center insight for an account or zone, removing it from the
        active insights list while preserving historical data.

        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 not issue_id:
            raise ValueError(f"Expected a non-empty value for `issue_id` but received {issue_id!r}")
        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._put(
            path_template(
                "/{account_or_zone}/{account_or_zone_id}/security-center/insights/{issue_id}/dismiss",
                issue_id=issue_id,
                account_or_zone=account_or_zone,
                account_or_zone_id=account_or_zone_id,
            ),
            body=await async_maybe_transform({"dismiss": dismiss}, insight_dismiss_params.InsightDismissParams),
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            cast_to=InsightDismissResponse,
        )


class InsightsResourceWithRawResponse:
    def __init__(self, insights: InsightsResource) -> None:
        self._insights = insights

        self.list = to_raw_response_wrapper(
            insights.list,
        )
        self.dismiss = to_raw_response_wrapper(
            insights.dismiss,
        )

    @cached_property
    def class_(self) -> ClassResourceWithRawResponse:
        return ClassResourceWithRawResponse(self._insights.class_)

    @cached_property
    def severity(self) -> SeverityResourceWithRawResponse:
        return SeverityResourceWithRawResponse(self._insights.severity)

    @cached_property
    def type(self) -> TypeResourceWithRawResponse:
        return TypeResourceWithRawResponse(self._insights.type)

    @cached_property
    def audit_logs(self) -> AuditLogsResourceWithRawResponse:
        return AuditLogsResourceWithRawResponse(self._insights.audit_logs)

    @cached_property
    def classification(self) -> ClassificationResourceWithRawResponse:
        return ClassificationResourceWithRawResponse(self._insights.classification)

    @cached_property
    def context(self) -> ContextResourceWithRawResponse:
        return ContextResourceWithRawResponse(self._insights.context)


class AsyncInsightsResourceWithRawResponse:
    def __init__(self, insights: AsyncInsightsResource) -> None:
        self._insights = insights

        self.list = async_to_raw_response_wrapper(
            insights.list,
        )
        self.dismiss = async_to_raw_response_wrapper(
            insights.dismiss,
        )

    @cached_property
    def class_(self) -> AsyncClassResourceWithRawResponse:
        return AsyncClassResourceWithRawResponse(self._insights.class_)

    @cached_property
    def severity(self) -> AsyncSeverityResourceWithRawResponse:
        return AsyncSeverityResourceWithRawResponse(self._insights.severity)

    @cached_property
    def type(self) -> AsyncTypeResourceWithRawResponse:
        return AsyncTypeResourceWithRawResponse(self._insights.type)

    @cached_property
    def audit_logs(self) -> AsyncAuditLogsResourceWithRawResponse:
        return AsyncAuditLogsResourceWithRawResponse(self._insights.audit_logs)

    @cached_property
    def classification(self) -> AsyncClassificationResourceWithRawResponse:
        return AsyncClassificationResourceWithRawResponse(self._insights.classification)

    @cached_property
    def context(self) -> AsyncContextResourceWithRawResponse:
        return AsyncContextResourceWithRawResponse(self._insights.context)


class InsightsResourceWithStreamingResponse:
    def __init__(self, insights: InsightsResource) -> None:
        self._insights = insights

        self.list = to_streamed_response_wrapper(
            insights.list,
        )
        self.dismiss = to_streamed_response_wrapper(
            insights.dismiss,
        )

    @cached_property
    def class_(self) -> ClassResourceWithStreamingResponse:
        return ClassResourceWithStreamingResponse(self._insights.class_)

    @cached_property
    def severity(self) -> SeverityResourceWithStreamingResponse:
        return SeverityResourceWithStreamingResponse(self._insights.severity)

    @cached_property
    def type(self) -> TypeResourceWithStreamingResponse:
        return TypeResourceWithStreamingResponse(self._insights.type)

    @cached_property
    def audit_logs(self) -> AuditLogsResourceWithStreamingResponse:
        return AuditLogsResourceWithStreamingResponse(self._insights.audit_logs)

    @cached_property
    def classification(self) -> ClassificationResourceWithStreamingResponse:
        return ClassificationResourceWithStreamingResponse(self._insights.classification)

    @cached_property
    def context(self) -> ContextResourceWithStreamingResponse:
        return ContextResourceWithStreamingResponse(self._insights.context)


class AsyncInsightsResourceWithStreamingResponse:
    def __init__(self, insights: AsyncInsightsResource) -> None:
        self._insights = insights

        self.list = async_to_streamed_response_wrapper(
            insights.list,
        )
        self.dismiss = async_to_streamed_response_wrapper(
            insights.dismiss,
        )

    @cached_property
    def class_(self) -> AsyncClassResourceWithStreamingResponse:
        return AsyncClassResourceWithStreamingResponse(self._insights.class_)

    @cached_property
    def severity(self) -> AsyncSeverityResourceWithStreamingResponse:
        return AsyncSeverityResourceWithStreamingResponse(self._insights.severity)

    @cached_property
    def type(self) -> AsyncTypeResourceWithStreamingResponse:
        return AsyncTypeResourceWithStreamingResponse(self._insights.type)

    @cached_property
    def audit_logs(self) -> AsyncAuditLogsResourceWithStreamingResponse:
        return AsyncAuditLogsResourceWithStreamingResponse(self._insights.audit_logs)

    @cached_property
    def classification(self) -> AsyncClassificationResourceWithStreamingResponse:
        return AsyncClassificationResourceWithStreamingResponse(self._insights.classification)

    @cached_property
    def context(self) -> AsyncContextResourceWithStreamingResponse:
        return AsyncContextResourceWithStreamingResponse(self._insights.context)
