# This file was auto-generated by Fern from our API Definition.

import typing
from json.decoder import JSONDecodeError

from ..core.api_error import ApiError
from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.http_response import AsyncHttpResponse, HttpResponse
from ..core.pydantic_utilities import parse_obj_as
from ..core.request_options import RequestOptions
from ..core.serialization import convert_and_respect_annotation_metadata
from ..errors.bad_request_error import BadRequestError
from ..errors.forbidden_error import ForbiddenError
from ..errors.internal_server_error import InternalServerError
from ..errors.request_timeout_error import RequestTimeoutError
from ..errors.too_many_requests_error import TooManyRequestsError
from ..errors.unauthorized_error import UnauthorizedError
from ..errors.unprocessable_entity_error import UnprocessableEntityError
from ..types.breaking_news_response_dto import BreakingNewsResponseDto
from ..types.content_sentiment_max import ContentSentimentMax
from ..types.content_sentiment_min import ContentSentimentMin
from ..types.error import Error
from ..types.from_rank import FromRank
from ..types.has_nlp import HasNlp
from ..types.include_nlp_data import IncludeNlpData
from ..types.include_translation_fields import IncludeTranslationFields
from ..types.loc_entity_name import LocEntityName
from ..types.misc_entity_name import MiscEntityName
from ..types.not_theme import NotTheme
from ..types.org_entity_name import OrgEntityName
from ..types.page import Page
from ..types.page_size import PageSize
from ..types.per_entity_name import PerEntityName
from ..types.ranked_only import RankedOnly
from ..types.robots_compliant import RobotsCompliant
from ..types.sort_by import SortBy
from ..types.theme import Theme
from ..types.title_sentiment_max import TitleSentimentMax
from ..types.title_sentiment_min import TitleSentimentMin
from ..types.to_rank import ToRank
from ..types.top_n_articles import TopNArticles
from .types.breaking_news_get_request_sort_by import BreakingNewsGetRequestSortBy

# this is used as the default value for optional parameters
OMIT = typing.cast(typing.Any, ...)


class RawBreakingNewsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._client_wrapper = client_wrapper

    def breaking_news_get(
        self,
        *,
        sort_by: typing.Optional[BreakingNewsGetRequestSortBy] = None,
        ranked_only: typing.Optional[bool] = None,
        from_rank: typing.Optional[int] = None,
        to_rank: typing.Optional[int] = None,
        page: typing.Optional[int] = None,
        page_size: typing.Optional[int] = None,
        top_n_articles: typing.Optional[TopNArticles] = None,
        include_translation_fields: typing.Optional[IncludeTranslationFields] = None,
        include_nlp_data: typing.Optional[IncludeNlpData] = None,
        has_nlp: typing.Optional[HasNlp] = None,
        theme: typing.Optional[str] = None,
        not_theme: typing.Optional[str] = None,
        org_entity_name: typing.Optional[str] = None,
        per_entity_name: typing.Optional[str] = None,
        loc_entity_name: typing.Optional[str] = None,
        misc_entity_name: typing.Optional[str] = None,
        title_sentiment_min: typing.Optional[float] = None,
        title_sentiment_max: typing.Optional[float] = None,
        content_sentiment_min: typing.Optional[float] = None,
        content_sentiment_max: typing.Optional[float] = None,
        robots_compliant: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[BreakingNewsResponseDto]:
        """
        Retrieves breaking news articles and sorts them based on specified criteria.

        Parameters
        ----------
        sort_by : typing.Optional[BreakingNewsGetRequestSortBy]
            The sorting order of the results. Possible values are:
            - `relevancy`: The most relevant results first.
            - `date`: The most recently published results first.
            - `rank`: The results from the highest-ranked sources first.

        ranked_only : typing.Optional[bool]
            If true, limits the search to sources ranked in the top 1 million online websites. If false, includes unranked sources which are assigned a rank of 999999.

        from_rank : typing.Optional[int]
            The lowest boundary of the rank of a news website to filter by. A lower rank indicates a more popular source.

        to_rank : typing.Optional[int]
            The highest boundary of the rank of a news website to filter by. A lower rank indicates a more popular source.

        page : typing.Optional[int]
            The page number to scroll through the results. Use for pagination, as a single API response can return up to 1,000 articles.

            For details, see [How to paginate large datasets](https://www.newscatcherapi.com/docs/v3/documentation/how-to/paginate-large-datasets).

        page_size : typing.Optional[int]
            The number of articles to return per page.

        top_n_articles : typing.Optional[TopNArticles]

        include_translation_fields : typing.Optional[IncludeTranslationFields]

        include_nlp_data : typing.Optional[IncludeNlpData]

        has_nlp : typing.Optional[HasNlp]

        theme : typing.Optional[str]
            Filters articles based on their general topic, as determined by NLP analysis. To select multiple themes, use a comma-separated string.

            Example: `"Finance, Tech"`

            **Note**: The `theme` parameter is only available if NLP is included in your subscription plan.

            To learn more, see [NLP features](/docs/v3/documentation/guides-and-concepts/nlp-features).

            Available options: `Business`, `Economics`, `Entertainment`, `Finance`, `Health`, `Politics`, `Science`, `Sports`, `Tech`, `Crime`, `Financial Crime`, `Lifestyle`, `Automotive`, `Travel`, `Weather`, `General`.

        not_theme : typing.Optional[str]
            Inverse of the `theme` parameter. Excludes articles based on their general topic, as determined by NLP analysis. To exclude multiple themes, use a comma-separated string.

            Example: `"Crime, Tech"`

            **Note**: The `not_theme` parameter is only available if NLP is included in your subscription plan.

            To learn more, see [NLP features](/docs/v3/documentation/guides-and-concepts/nlp-features).

        org_entity_name : typing.Optional[str]
            Filters articles that mention specific organization names, as identified by NLP analysis. To specify multiple organizations, use a comma-separated string. To search named entities in translations, combine with the translation options of the `search_in` parameter (e.g., `title_content_translated`).

            Example: `"Apple, Microsoft"`

            **Note**: The `ORG_entity_name` parameter is only available if NLP is included in your subscription plan.

            To learn more, see [Search by entity](/docs/v3/documentation/how-to/search-by-entity).

        per_entity_name : typing.Optional[str]
            Filters articles that mention specific person names, as identified by NLP analysis. To specify multiple names, use a comma-separated string. To search named entities in translations, combine with the translation options of the `search_in` parameter (e.g., `title_content_translated`).

            Example: `"Elon Musk, Jeff Bezos"`

            **Note**: The `PER_entity_name` parameter is only available if NLP is included in your subscription plan.

            To learn more, see [Search by entity](/docs/v3/documentation/how-to/search-by-entity).

        loc_entity_name : typing.Optional[str]
            Filters articles that mention specific location names, as identified by NLP analysis. To specify multiple locations, use a comma-separated string. To search named entities in translations, combine with the translation options of the `search_in` parameter (e.g., `title_content_translated`).

            Example: `"California, New York"`

            **Note**: The `LOC_entity_name` parameter is only available if NLP is included in your subscription plan.

            To learn more, see [Search by entity](/docs/v3/documentation/how-to/search-by-entity).

        misc_entity_name : typing.Optional[str]
            Filters articles that mention other named entities not falling under person, organization, or location categories. Includes events, nationalities, products, works of art, and more. To specify multiple entities, use a comma-separated string. To search named entities in translations, combine with the translation options of the `search_in` parameter (e.g., `title_content_translated`).

            Example: `"Bitcoin, Blockchain"`

            **Note**: The `MISC_entity_name` parameter is only available if NLP is included in your subscription plan.

            To learn more, see [Search by entity](/docs/v3/documentation/how-to/search-by-entity).

        title_sentiment_min : typing.Optional[float]
            Filters articles based on the minimum sentiment score of their titles.

            Range is `-1.0` to `1.0`, where:
            - Negative values indicate negative sentiment.
            - Positive values indicate positive sentiment.
            - Values close to 0 indicate neutral sentiment.

            **Note**: The `title_sentiment_min` parameter is only available if NLP is included in your subscription plan.

            To learn more, see [NLP features](/docs/v3/documentation/guides-and-concepts/nlp-features).

        title_sentiment_max : typing.Optional[float]
            Filters articles based on the maximum sentiment score of their titles.

            Range is `-1.0` to `1.0`, where:
            - Negative values indicate negative sentiment.
            - Positive values indicate positive sentiment.
            - Values close to 0 indicate neutral sentiment.

            **Note**: The `title_sentiment_max` parameter is only available if NLP is included in your subscription plan.

            To learn more, see [NLP features](/docs/v3/documentation/guides-and-concepts/nlp-features).

        content_sentiment_min : typing.Optional[float]
            Filters articles based on the minimum sentiment score of their content.

            Range is `-1.0` to `1.0`, where:
            - Negative values indicate negative sentiment.
            - Positive values indicate positive sentiment.
            - Values close to 0 indicate neutral sentiment.

            **Note**: The `content_sentiment_min` parameter is only available if NLP is included in your subscription plan.

            To learn more, see [NLP features](/docs/v3/documentation/guides-and-concepts/nlp-features).

        content_sentiment_max : typing.Optional[float]
            Filters articles based on the maximum sentiment score of their content.

            Range is `-1.0` to `1.0`, where:
            - Negative values indicate negative sentiment.
            - Positive values indicate positive sentiment.
            - Values close to 0 indicate neutral sentiment.

            **Note**: The `content_sentiment_max` parameter is only available if NLP is included in your subscription plan.

            To learn more, see [NLP features](/docs/v3/documentation/guides-and-concepts/nlp-features).

        robots_compliant : typing.Optional[bool]
            If true, returns only articles/sources that comply with the publisher's robots.txt rules. If false, returns only articles/sources that do not comply with robots.txt rules. If omitted, returns all articles/sources regardless of compliance status.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[BreakingNewsResponseDto]
            A successful response containing breaking news articles with additional breaking news event information.
        """
        _response = self._client_wrapper.httpx_client.request(
            "api/breaking_news",
            method="GET",
            params={
                "sort_by": sort_by,
                "ranked_only": ranked_only,
                "from_rank": from_rank,
                "to_rank": to_rank,
                "page": page,
                "page_size": page_size,
                "top_n_articles": top_n_articles,
                "include_translation_fields": include_translation_fields,
                "include_nlp_data": include_nlp_data,
                "has_nlp": has_nlp,
                "theme": theme,
                "not_theme": not_theme,
                "ORG_entity_name": org_entity_name,
                "PER_entity_name": per_entity_name,
                "LOC_entity_name": loc_entity_name,
                "MISC_entity_name": misc_entity_name,
                "title_sentiment_min": title_sentiment_min,
                "title_sentiment_max": title_sentiment_max,
                "content_sentiment_min": content_sentiment_min,
                "content_sentiment_max": content_sentiment_max,
                "robots_compliant": robots_compliant,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    BreakingNewsResponseDto,
                    parse_obj_as(
                        type_=BreakingNewsResponseDto,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Error,
                        parse_obj_as(
                            type_=Error,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Error,
                        parse_obj_as(
                            type_=Error,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise ForbiddenError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Error,
                        parse_obj_as(
                            type_=Error,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 408:
                raise RequestTimeoutError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Error,
                        parse_obj_as(
                            type_=Error,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Error,
                        parse_obj_as(
                            type_=Error,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 429:
                raise TooManyRequestsError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Error,
                        parse_obj_as(
                            type_=Error,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        str,
                        parse_obj_as(
                            type_=str,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def breaking_news_post(
        self,
        *,
        sort_by: typing.Optional[SortBy] = OMIT,
        ranked_only: typing.Optional[RankedOnly] = OMIT,
        from_rank: typing.Optional[FromRank] = OMIT,
        to_rank: typing.Optional[ToRank] = OMIT,
        page: typing.Optional[Page] = OMIT,
        page_size: typing.Optional[PageSize] = OMIT,
        top_n_articles: typing.Optional[TopNArticles] = OMIT,
        include_translation_fields: typing.Optional[IncludeTranslationFields] = OMIT,
        include_nlp_data: typing.Optional[IncludeNlpData] = OMIT,
        has_nlp: typing.Optional[HasNlp] = OMIT,
        theme: typing.Optional[Theme] = OMIT,
        not_theme: typing.Optional[NotTheme] = OMIT,
        org_entity_name: typing.Optional[OrgEntityName] = OMIT,
        per_entity_name: typing.Optional[PerEntityName] = OMIT,
        loc_entity_name: typing.Optional[LocEntityName] = OMIT,
        misc_entity_name: typing.Optional[MiscEntityName] = OMIT,
        title_sentiment_min: typing.Optional[TitleSentimentMin] = OMIT,
        title_sentiment_max: typing.Optional[TitleSentimentMax] = OMIT,
        content_sentiment_min: typing.Optional[ContentSentimentMin] = OMIT,
        content_sentient_max: typing.Optional[ContentSentimentMax] = OMIT,
        robots_compliant: typing.Optional[RobotsCompliant] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[BreakingNewsResponseDto]:
        """
        Retrieves breaking news articles and sorts them based on specified criteria.

        Parameters
        ----------
        sort_by : typing.Optional[SortBy]

        ranked_only : typing.Optional[RankedOnly]

        from_rank : typing.Optional[FromRank]

        to_rank : typing.Optional[ToRank]

        page : typing.Optional[Page]

        page_size : typing.Optional[PageSize]

        top_n_articles : typing.Optional[TopNArticles]

        include_translation_fields : typing.Optional[IncludeTranslationFields]

        include_nlp_data : typing.Optional[IncludeNlpData]

        has_nlp : typing.Optional[HasNlp]

        theme : typing.Optional[Theme]

        not_theme : typing.Optional[NotTheme]

        org_entity_name : typing.Optional[OrgEntityName]

        per_entity_name : typing.Optional[PerEntityName]

        loc_entity_name : typing.Optional[LocEntityName]

        misc_entity_name : typing.Optional[MiscEntityName]

        title_sentiment_min : typing.Optional[TitleSentimentMin]

        title_sentiment_max : typing.Optional[TitleSentimentMax]

        content_sentiment_min : typing.Optional[ContentSentimentMin]

        content_sentient_max : typing.Optional[ContentSentimentMax]

        robots_compliant : typing.Optional[RobotsCompliant]

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[BreakingNewsResponseDto]
            A successful response containing breaking news articles with additional breaking news event information.
        """
        _response = self._client_wrapper.httpx_client.request(
            "api/breaking_news",
            method="POST",
            json={
                "sort_by": sort_by,
                "ranked_only": ranked_only,
                "from_rank": from_rank,
                "to_rank": to_rank,
                "page": page,
                "page_size": page_size,
                "top_n_articles": top_n_articles,
                "include_translation_fields": include_translation_fields,
                "include_nlp_data": include_nlp_data,
                "has_nlp": has_nlp,
                "theme": convert_and_respect_annotation_metadata(object_=theme, annotation=Theme, direction="write"),
                "not_theme": convert_and_respect_annotation_metadata(
                    object_=not_theme, annotation=NotTheme, direction="write"
                ),
                "ORG_entity_name": org_entity_name,
                "PER_entity_name": per_entity_name,
                "LOC_entity_name": loc_entity_name,
                "MISC_entity_name": misc_entity_name,
                "title_sentiment_min": title_sentiment_min,
                "title_sentiment_max": title_sentiment_max,
                "content_sentiment_min": content_sentiment_min,
                "content_sentient_max": content_sentient_max,
                "robots_compliant": robots_compliant,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    BreakingNewsResponseDto,
                    parse_obj_as(
                        type_=BreakingNewsResponseDto,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Error,
                        parse_obj_as(
                            type_=Error,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Error,
                        parse_obj_as(
                            type_=Error,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise ForbiddenError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Error,
                        parse_obj_as(
                            type_=Error,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 408:
                raise RequestTimeoutError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Error,
                        parse_obj_as(
                            type_=Error,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Error,
                        parse_obj_as(
                            type_=Error,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 429:
                raise TooManyRequestsError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Error,
                        parse_obj_as(
                            type_=Error,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        str,
                        parse_obj_as(
                            type_=str,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)


class AsyncRawBreakingNewsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._client_wrapper = client_wrapper

    async def breaking_news_get(
        self,
        *,
        sort_by: typing.Optional[BreakingNewsGetRequestSortBy] = None,
        ranked_only: typing.Optional[bool] = None,
        from_rank: typing.Optional[int] = None,
        to_rank: typing.Optional[int] = None,
        page: typing.Optional[int] = None,
        page_size: typing.Optional[int] = None,
        top_n_articles: typing.Optional[TopNArticles] = None,
        include_translation_fields: typing.Optional[IncludeTranslationFields] = None,
        include_nlp_data: typing.Optional[IncludeNlpData] = None,
        has_nlp: typing.Optional[HasNlp] = None,
        theme: typing.Optional[str] = None,
        not_theme: typing.Optional[str] = None,
        org_entity_name: typing.Optional[str] = None,
        per_entity_name: typing.Optional[str] = None,
        loc_entity_name: typing.Optional[str] = None,
        misc_entity_name: typing.Optional[str] = None,
        title_sentiment_min: typing.Optional[float] = None,
        title_sentiment_max: typing.Optional[float] = None,
        content_sentiment_min: typing.Optional[float] = None,
        content_sentiment_max: typing.Optional[float] = None,
        robots_compliant: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[BreakingNewsResponseDto]:
        """
        Retrieves breaking news articles and sorts them based on specified criteria.

        Parameters
        ----------
        sort_by : typing.Optional[BreakingNewsGetRequestSortBy]
            The sorting order of the results. Possible values are:
            - `relevancy`: The most relevant results first.
            - `date`: The most recently published results first.
            - `rank`: The results from the highest-ranked sources first.

        ranked_only : typing.Optional[bool]
            If true, limits the search to sources ranked in the top 1 million online websites. If false, includes unranked sources which are assigned a rank of 999999.

        from_rank : typing.Optional[int]
            The lowest boundary of the rank of a news website to filter by. A lower rank indicates a more popular source.

        to_rank : typing.Optional[int]
            The highest boundary of the rank of a news website to filter by. A lower rank indicates a more popular source.

        page : typing.Optional[int]
            The page number to scroll through the results. Use for pagination, as a single API response can return up to 1,000 articles.

            For details, see [How to paginate large datasets](https://www.newscatcherapi.com/docs/v3/documentation/how-to/paginate-large-datasets).

        page_size : typing.Optional[int]
            The number of articles to return per page.

        top_n_articles : typing.Optional[TopNArticles]

        include_translation_fields : typing.Optional[IncludeTranslationFields]

        include_nlp_data : typing.Optional[IncludeNlpData]

        has_nlp : typing.Optional[HasNlp]

        theme : typing.Optional[str]
            Filters articles based on their general topic, as determined by NLP analysis. To select multiple themes, use a comma-separated string.

            Example: `"Finance, Tech"`

            **Note**: The `theme` parameter is only available if NLP is included in your subscription plan.

            To learn more, see [NLP features](/docs/v3/documentation/guides-and-concepts/nlp-features).

            Available options: `Business`, `Economics`, `Entertainment`, `Finance`, `Health`, `Politics`, `Science`, `Sports`, `Tech`, `Crime`, `Financial Crime`, `Lifestyle`, `Automotive`, `Travel`, `Weather`, `General`.

        not_theme : typing.Optional[str]
            Inverse of the `theme` parameter. Excludes articles based on their general topic, as determined by NLP analysis. To exclude multiple themes, use a comma-separated string.

            Example: `"Crime, Tech"`

            **Note**: The `not_theme` parameter is only available if NLP is included in your subscription plan.

            To learn more, see [NLP features](/docs/v3/documentation/guides-and-concepts/nlp-features).

        org_entity_name : typing.Optional[str]
            Filters articles that mention specific organization names, as identified by NLP analysis. To specify multiple organizations, use a comma-separated string. To search named entities in translations, combine with the translation options of the `search_in` parameter (e.g., `title_content_translated`).

            Example: `"Apple, Microsoft"`

            **Note**: The `ORG_entity_name` parameter is only available if NLP is included in your subscription plan.

            To learn more, see [Search by entity](/docs/v3/documentation/how-to/search-by-entity).

        per_entity_name : typing.Optional[str]
            Filters articles that mention specific person names, as identified by NLP analysis. To specify multiple names, use a comma-separated string. To search named entities in translations, combine with the translation options of the `search_in` parameter (e.g., `title_content_translated`).

            Example: `"Elon Musk, Jeff Bezos"`

            **Note**: The `PER_entity_name` parameter is only available if NLP is included in your subscription plan.

            To learn more, see [Search by entity](/docs/v3/documentation/how-to/search-by-entity).

        loc_entity_name : typing.Optional[str]
            Filters articles that mention specific location names, as identified by NLP analysis. To specify multiple locations, use a comma-separated string. To search named entities in translations, combine with the translation options of the `search_in` parameter (e.g., `title_content_translated`).

            Example: `"California, New York"`

            **Note**: The `LOC_entity_name` parameter is only available if NLP is included in your subscription plan.

            To learn more, see [Search by entity](/docs/v3/documentation/how-to/search-by-entity).

        misc_entity_name : typing.Optional[str]
            Filters articles that mention other named entities not falling under person, organization, or location categories. Includes events, nationalities, products, works of art, and more. To specify multiple entities, use a comma-separated string. To search named entities in translations, combine with the translation options of the `search_in` parameter (e.g., `title_content_translated`).

            Example: `"Bitcoin, Blockchain"`

            **Note**: The `MISC_entity_name` parameter is only available if NLP is included in your subscription plan.

            To learn more, see [Search by entity](/docs/v3/documentation/how-to/search-by-entity).

        title_sentiment_min : typing.Optional[float]
            Filters articles based on the minimum sentiment score of their titles.

            Range is `-1.0` to `1.0`, where:
            - Negative values indicate negative sentiment.
            - Positive values indicate positive sentiment.
            - Values close to 0 indicate neutral sentiment.

            **Note**: The `title_sentiment_min` parameter is only available if NLP is included in your subscription plan.

            To learn more, see [NLP features](/docs/v3/documentation/guides-and-concepts/nlp-features).

        title_sentiment_max : typing.Optional[float]
            Filters articles based on the maximum sentiment score of their titles.

            Range is `-1.0` to `1.0`, where:
            - Negative values indicate negative sentiment.
            - Positive values indicate positive sentiment.
            - Values close to 0 indicate neutral sentiment.

            **Note**: The `title_sentiment_max` parameter is only available if NLP is included in your subscription plan.

            To learn more, see [NLP features](/docs/v3/documentation/guides-and-concepts/nlp-features).

        content_sentiment_min : typing.Optional[float]
            Filters articles based on the minimum sentiment score of their content.

            Range is `-1.0` to `1.0`, where:
            - Negative values indicate negative sentiment.
            - Positive values indicate positive sentiment.
            - Values close to 0 indicate neutral sentiment.

            **Note**: The `content_sentiment_min` parameter is only available if NLP is included in your subscription plan.

            To learn more, see [NLP features](/docs/v3/documentation/guides-and-concepts/nlp-features).

        content_sentiment_max : typing.Optional[float]
            Filters articles based on the maximum sentiment score of their content.

            Range is `-1.0` to `1.0`, where:
            - Negative values indicate negative sentiment.
            - Positive values indicate positive sentiment.
            - Values close to 0 indicate neutral sentiment.

            **Note**: The `content_sentiment_max` parameter is only available if NLP is included in your subscription plan.

            To learn more, see [NLP features](/docs/v3/documentation/guides-and-concepts/nlp-features).

        robots_compliant : typing.Optional[bool]
            If true, returns only articles/sources that comply with the publisher's robots.txt rules. If false, returns only articles/sources that do not comply with robots.txt rules. If omitted, returns all articles/sources regardless of compliance status.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[BreakingNewsResponseDto]
            A successful response containing breaking news articles with additional breaking news event information.
        """
        _response = await self._client_wrapper.httpx_client.request(
            "api/breaking_news",
            method="GET",
            params={
                "sort_by": sort_by,
                "ranked_only": ranked_only,
                "from_rank": from_rank,
                "to_rank": to_rank,
                "page": page,
                "page_size": page_size,
                "top_n_articles": top_n_articles,
                "include_translation_fields": include_translation_fields,
                "include_nlp_data": include_nlp_data,
                "has_nlp": has_nlp,
                "theme": theme,
                "not_theme": not_theme,
                "ORG_entity_name": org_entity_name,
                "PER_entity_name": per_entity_name,
                "LOC_entity_name": loc_entity_name,
                "MISC_entity_name": misc_entity_name,
                "title_sentiment_min": title_sentiment_min,
                "title_sentiment_max": title_sentiment_max,
                "content_sentiment_min": content_sentiment_min,
                "content_sentiment_max": content_sentiment_max,
                "robots_compliant": robots_compliant,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    BreakingNewsResponseDto,
                    parse_obj_as(
                        type_=BreakingNewsResponseDto,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Error,
                        parse_obj_as(
                            type_=Error,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Error,
                        parse_obj_as(
                            type_=Error,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise ForbiddenError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Error,
                        parse_obj_as(
                            type_=Error,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 408:
                raise RequestTimeoutError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Error,
                        parse_obj_as(
                            type_=Error,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Error,
                        parse_obj_as(
                            type_=Error,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 429:
                raise TooManyRequestsError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Error,
                        parse_obj_as(
                            type_=Error,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        str,
                        parse_obj_as(
                            type_=str,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def breaking_news_post(
        self,
        *,
        sort_by: typing.Optional[SortBy] = OMIT,
        ranked_only: typing.Optional[RankedOnly] = OMIT,
        from_rank: typing.Optional[FromRank] = OMIT,
        to_rank: typing.Optional[ToRank] = OMIT,
        page: typing.Optional[Page] = OMIT,
        page_size: typing.Optional[PageSize] = OMIT,
        top_n_articles: typing.Optional[TopNArticles] = OMIT,
        include_translation_fields: typing.Optional[IncludeTranslationFields] = OMIT,
        include_nlp_data: typing.Optional[IncludeNlpData] = OMIT,
        has_nlp: typing.Optional[HasNlp] = OMIT,
        theme: typing.Optional[Theme] = OMIT,
        not_theme: typing.Optional[NotTheme] = OMIT,
        org_entity_name: typing.Optional[OrgEntityName] = OMIT,
        per_entity_name: typing.Optional[PerEntityName] = OMIT,
        loc_entity_name: typing.Optional[LocEntityName] = OMIT,
        misc_entity_name: typing.Optional[MiscEntityName] = OMIT,
        title_sentiment_min: typing.Optional[TitleSentimentMin] = OMIT,
        title_sentiment_max: typing.Optional[TitleSentimentMax] = OMIT,
        content_sentiment_min: typing.Optional[ContentSentimentMin] = OMIT,
        content_sentient_max: typing.Optional[ContentSentimentMax] = OMIT,
        robots_compliant: typing.Optional[RobotsCompliant] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[BreakingNewsResponseDto]:
        """
        Retrieves breaking news articles and sorts them based on specified criteria.

        Parameters
        ----------
        sort_by : typing.Optional[SortBy]

        ranked_only : typing.Optional[RankedOnly]

        from_rank : typing.Optional[FromRank]

        to_rank : typing.Optional[ToRank]

        page : typing.Optional[Page]

        page_size : typing.Optional[PageSize]

        top_n_articles : typing.Optional[TopNArticles]

        include_translation_fields : typing.Optional[IncludeTranslationFields]

        include_nlp_data : typing.Optional[IncludeNlpData]

        has_nlp : typing.Optional[HasNlp]

        theme : typing.Optional[Theme]

        not_theme : typing.Optional[NotTheme]

        org_entity_name : typing.Optional[OrgEntityName]

        per_entity_name : typing.Optional[PerEntityName]

        loc_entity_name : typing.Optional[LocEntityName]

        misc_entity_name : typing.Optional[MiscEntityName]

        title_sentiment_min : typing.Optional[TitleSentimentMin]

        title_sentiment_max : typing.Optional[TitleSentimentMax]

        content_sentiment_min : typing.Optional[ContentSentimentMin]

        content_sentient_max : typing.Optional[ContentSentimentMax]

        robots_compliant : typing.Optional[RobotsCompliant]

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[BreakingNewsResponseDto]
            A successful response containing breaking news articles with additional breaking news event information.
        """
        _response = await self._client_wrapper.httpx_client.request(
            "api/breaking_news",
            method="POST",
            json={
                "sort_by": sort_by,
                "ranked_only": ranked_only,
                "from_rank": from_rank,
                "to_rank": to_rank,
                "page": page,
                "page_size": page_size,
                "top_n_articles": top_n_articles,
                "include_translation_fields": include_translation_fields,
                "include_nlp_data": include_nlp_data,
                "has_nlp": has_nlp,
                "theme": convert_and_respect_annotation_metadata(object_=theme, annotation=Theme, direction="write"),
                "not_theme": convert_and_respect_annotation_metadata(
                    object_=not_theme, annotation=NotTheme, direction="write"
                ),
                "ORG_entity_name": org_entity_name,
                "PER_entity_name": per_entity_name,
                "LOC_entity_name": loc_entity_name,
                "MISC_entity_name": misc_entity_name,
                "title_sentiment_min": title_sentiment_min,
                "title_sentiment_max": title_sentiment_max,
                "content_sentiment_min": content_sentiment_min,
                "content_sentient_max": content_sentient_max,
                "robots_compliant": robots_compliant,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    BreakingNewsResponseDto,
                    parse_obj_as(
                        type_=BreakingNewsResponseDto,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Error,
                        parse_obj_as(
                            type_=Error,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Error,
                        parse_obj_as(
                            type_=Error,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise ForbiddenError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Error,
                        parse_obj_as(
                            type_=Error,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 408:
                raise RequestTimeoutError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Error,
                        parse_obj_as(
                            type_=Error,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Error,
                        parse_obj_as(
                            type_=Error,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 429:
                raise TooManyRequestsError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Error,
                        parse_obj_as(
                            type_=Error,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        str,
                        parse_obj_as(
                            type_=str,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
