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

import typing

import httpx
from .core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from .core.request_options import RequestOptions
from .environment import WhoisfreaksApiEnvironment
from .raw_client import AsyncRawWhoisfreaksApi, RawWhoisfreaksApi
from .types.get_dns_records_request_data_type import GetDnsRecordsRequestDataType
from .types.get_dns_records_request_type import GetDnsRecordsRequestType
from .types.get_live_historical_or_reverse_whois_request_whois import GetLiveHistoricalOrReverseWhoisRequestWhois


class WhoisfreaksApi:
    """
    Use this class to access the different functions within the SDK. You can instantiate any number of clients with different configuration that will propagate to these functions.

    Parameters
    ----------
    base_url : typing.Optional[str]
        The base url to use for requests from the client.

    environment : WhoisfreaksApiEnvironment
        The environment to use for requests from the client. from .environment import WhoisfreaksApiEnvironment

        Defaults to WhoisfreaksApiEnvironment.DEFAULT



    timeout : typing.Optional[float]
        The timeout to be used, in seconds, for requests. By default the timeout is 60 seconds, unless a custom httpx client is used, in which case this default is not enforced.

    follow_redirects : typing.Optional[bool]
        Whether the default httpx client follows redirects or not, this is irrelevant if a custom httpx client is passed in.

    httpx_client : typing.Optional[httpx.Client]
        The httpx client to use for making requests, a preconfigured client is used by default, however this is useful should you want to pass in any custom httpx configuration.

    Examples
    --------
    from whoisfreaks import WhoisfreaksApi
    client = WhoisfreaksApi()
    """

    def __init__(
        self,
        *,
        base_url: typing.Optional[str] = None,
        environment: WhoisfreaksApiEnvironment = WhoisfreaksApiEnvironment.DEFAULT,
        timeout: typing.Optional[float] = None,
        follow_redirects: typing.Optional[bool] = True,
        httpx_client: typing.Optional[httpx.Client] = None,
    ):
        _defaulted_timeout = (
            timeout if timeout is not None else 60 if httpx_client is None else httpx_client.timeout.read
        )
        self._client_wrapper = SyncClientWrapper(
            base_url=_get_base_url(base_url=base_url, environment=environment),
            httpx_client=httpx_client
            if httpx_client is not None
            else httpx.Client(timeout=_defaulted_timeout, follow_redirects=follow_redirects)
            if follow_redirects is not None
            else httpx.Client(timeout=_defaulted_timeout),
            timeout=_defaulted_timeout,
        )
        self._raw_client = RawWhoisfreaksApi(client_wrapper=self._client_wrapper)

    @property
    def with_raw_response(self) -> RawWhoisfreaksApi:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        RawWhoisfreaksApi
        """
        return self._raw_client

    def get_live_historical_or_reverse_whois(
        self,
        *,
        whois: GetLiveHistoricalOrReverseWhoisRequestWhois,
        domain_name: typing.Optional[str] = None,
        keyword: typing.Optional[str] = None,
        email: typing.Optional[str] = None,
        owner: typing.Optional[str] = None,
        company: typing.Optional[str] = None,
        mode: typing.Optional[typing.Literal["mini"]] = None,
        page: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Dict[str, typing.Optional[typing.Any]]:
        """
        Retrieves Live, Historical or Reverse WHOIS information based on the specified parameters.
        #ExamplePrompt Give me ownership details of ipgeolocation.io using whoisfreaks

        Parameters
        ----------
        whois : GetLiveHistoricalOrReverseWhoisRequestWhois
            Type of WHOIS data to retrieve (e.g., live, historical, reverse)

        domain_name : typing.Optional[str]
            The domain name for retrieving live or historical WHOIS information. Note that reverse lookup does not support domain-based searches.

        keyword : typing.Optional[str]
            Keyword for reverse WHOIS lookup

        email : typing.Optional[str]
            Email address for reverse WHOIS lookup

        owner : typing.Optional[str]
            Owner name for reverse WHOIS lookup

        company : typing.Optional[str]
            Company name for reverse WHOIS lookup

        mode : typing.Optional[typing.Literal["mini"]]
            Mode for reverse WHOIS lookup (e.g., mini)

        page : typing.Optional[int]
            Page number for paginated results

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

        Returns
        -------
        typing.Dict[str, typing.Optional[typing.Any]]
            Successful response

        Examples
        --------
        from whoisfreaks import WhoisfreaksApi
        client = WhoisfreaksApi()
        client.get_live_historical_or_reverse_whois(whois="live", domain_name='whoisfreaks.com', keyword='whois', email='abc@xyz.com', owner='ejaz', company='jfreaks', )
        """
        _response = self._raw_client.get_live_historical_or_reverse_whois(
            whois=whois,
            domain_name=domain_name,
            keyword=keyword,
            email=email,
            owner=owner,
            company=company,
            mode=mode,
            page=page,
            request_options=request_options,
        )
        return _response.data

    def get_dns_records(
        self,
        data_type: GetDnsRecordsRequestDataType,
        *,
        type: GetDnsRecordsRequestType,
        domain_name: typing.Optional[str] = None,
        value: typing.Optional[str] = None,
        page: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Dict[str, typing.Optional[typing.Any]]:
        """
        Retrieves live and historical records or dns data for a specified domain OR reverse DNS records for the specified data like IPV4 in case of A record and similarly for other supported records too.
        #ExamplePrompt Give me reverse DNS data for mx.zoho.com

        Parameters
        ----------
        data_type : GetDnsRecordsRequestDataType
            Type of DNS operation (live, historical, reverse)

        type : GetDnsRecordsRequestType
            Type of DNS records to retrieve. Possible values are [A, AAAA, NS, MX, CNAME, TXT, SPF, SOA, all]. When data_type is 'reverse', 'all' is not allowed.

        domain_name : typing.Optional[str]
            Domain name to retrieve DNS records for

        value : typing.Optional[str]
            Value to perform reverse DNS lookup on (e.g., IP address, domain name, etc.)

        page : typing.Optional[int]
            Page number for paginated results

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

        Returns
        -------
        typing.Dict[str, typing.Optional[typing.Any]]
            Successful response

        Examples
        --------
        from whoisfreaks import WhoisfreaksApi
        client = WhoisfreaksApi()
        client.get_dns_records(data_type="live", domain_name='whoisfreaks.com', value='8.8.8.8', type="A", )
        """
        _response = self._raw_client.get_dns_records(
            data_type, type=type, domain_name=domain_name, value=value, page=page, request_options=request_options
        )
        return _response.data

    def get_live_ssl_certificate(
        self,
        *,
        domain_name: str,
        chain: typing.Optional[bool] = None,
        ssl_raw: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Dict[str, typing.Optional[typing.Any]]:
        """
        Retrieves live SSL certificate information for the specified domain.
        #ExamplePrompt When does whoisfreaks.com' SSL certificate will be expired?

        Parameters
        ----------
        domain_name : str
            Domain name to retrieve SSL certificate information for

        chain : typing.Optional[bool]
            Whether to include the certificate chain

        ssl_raw : typing.Optional[bool]
            Whether to include the raw SSL data

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

        Returns
        -------
        typing.Dict[str, typing.Optional[typing.Any]]
            Successful response

        Examples
        --------
        from whoisfreaks import WhoisfreaksApi
        client = WhoisfreaksApi()
        client.get_live_ssl_certificate(domain_name='whoisfreaks.com', )
        """
        _response = self._raw_client.get_live_ssl_certificate(
            domain_name=domain_name, chain=chain, ssl_raw=ssl_raw, request_options=request_options
        )
        return _response.data

    def get_ip_whois(
        self, *, ip: str, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.Dict[str, typing.Optional[typing.Any]]:
        """
        Retrieves WHOIS information for the specified IP address.
        #ExamplePrompt give me WHOIS details of 8.8.8.8

        Parameters
        ----------
        ip : str
            IP address to retrieve WHOIS information for

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

        Returns
        -------
        typing.Dict[str, typing.Optional[typing.Any]]
            Successful response

        Examples
        --------
        from whoisfreaks import WhoisfreaksApi
        client = WhoisfreaksApi()
        client.get_ip_whois(ip='8.8.8.8', )
        """
        _response = self._raw_client.get_ip_whois(ip=ip, request_options=request_options)
        return _response.data

    def get_asn_whois(
        self, *, asn: str, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.Dict[str, typing.Optional[typing.Any]]:
        """
        Retrieves WHOIS information for the specified ASN.
        #ExamplePrompt 'AS13335' AS number belongs to which organization?

        Parameters
        ----------
        asn : str
            ASN to retrieve WHOIS information for

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

        Returns
        -------
        typing.Dict[str, typing.Optional[typing.Any]]
            Successful response

        Examples
        --------
        from whoisfreaks import WhoisfreaksApi
        client = WhoisfreaksApi()
        client.get_asn_whois(asn='AS56554', )
        """
        _response = self._raw_client.get_asn_whois(asn=asn, request_options=request_options)
        return _response.data

    def check_single_domain_availability(
        self,
        *,
        domain: str,
        sug: typing.Optional[bool] = None,
        count: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Dict[str, typing.Optional[typing.Any]]:
        """
        Checks the availability of the specified domain and provides suggestions if requested.
        #ExamplePrompt Is 'whoisfreaks.pk' a registered domain or not?

        Parameters
        ----------
        domain : str
            Domain to check availability for

        sug : typing.Optional[bool]
            Whether to provide domain suggestions

        count : typing.Optional[int]
            Number of suggestions to provide

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

        Returns
        -------
        typing.Dict[str, typing.Optional[typing.Any]]
            Successful response

        Examples
        --------
        from whoisfreaks import WhoisfreaksApi
        client = WhoisfreaksApi()
        client.check_single_domain_availability(domain='whoisfreaks.pk', )
        """
        _response = self._raw_client.check_single_domain_availability(
            domain=domain, sug=sug, count=count, request_options=request_options
        )
        return _response.data


class AsyncWhoisfreaksApi:
    """
    Use this class to access the different functions within the SDK. You can instantiate any number of clients with different configuration that will propagate to these functions.

    Parameters
    ----------
    base_url : typing.Optional[str]
        The base url to use for requests from the client.

    environment : WhoisfreaksApiEnvironment
        The environment to use for requests from the client. from .environment import WhoisfreaksApiEnvironment

        Defaults to WhoisfreaksApiEnvironment.DEFAULT



    timeout : typing.Optional[float]
        The timeout to be used, in seconds, for requests. By default the timeout is 60 seconds, unless a custom httpx client is used, in which case this default is not enforced.

    follow_redirects : typing.Optional[bool]
        Whether the default httpx client follows redirects or not, this is irrelevant if a custom httpx client is passed in.

    httpx_client : typing.Optional[httpx.AsyncClient]
        The httpx client to use for making requests, a preconfigured client is used by default, however this is useful should you want to pass in any custom httpx configuration.

    Examples
    --------
    from whoisfreaks import AsyncWhoisfreaksApi
    client = AsyncWhoisfreaksApi()
    """

    def __init__(
        self,
        *,
        base_url: typing.Optional[str] = None,
        environment: WhoisfreaksApiEnvironment = WhoisfreaksApiEnvironment.DEFAULT,
        timeout: typing.Optional[float] = None,
        follow_redirects: typing.Optional[bool] = True,
        httpx_client: typing.Optional[httpx.AsyncClient] = None,
    ):
        _defaulted_timeout = (
            timeout if timeout is not None else 60 if httpx_client is None else httpx_client.timeout.read
        )
        self._client_wrapper = AsyncClientWrapper(
            base_url=_get_base_url(base_url=base_url, environment=environment),
            httpx_client=httpx_client
            if httpx_client is not None
            else httpx.AsyncClient(timeout=_defaulted_timeout, follow_redirects=follow_redirects)
            if follow_redirects is not None
            else httpx.AsyncClient(timeout=_defaulted_timeout),
            timeout=_defaulted_timeout,
        )
        self._raw_client = AsyncRawWhoisfreaksApi(client_wrapper=self._client_wrapper)

    @property
    def with_raw_response(self) -> AsyncRawWhoisfreaksApi:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        AsyncRawWhoisfreaksApi
        """
        return self._raw_client

    async def get_live_historical_or_reverse_whois(
        self,
        *,
        whois: GetLiveHistoricalOrReverseWhoisRequestWhois,
        domain_name: typing.Optional[str] = None,
        keyword: typing.Optional[str] = None,
        email: typing.Optional[str] = None,
        owner: typing.Optional[str] = None,
        company: typing.Optional[str] = None,
        mode: typing.Optional[typing.Literal["mini"]] = None,
        page: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Dict[str, typing.Optional[typing.Any]]:
        """
        Retrieves Live, Historical or Reverse WHOIS information based on the specified parameters.
        #ExamplePrompt Give me ownership details of ipgeolocation.io using whoisfreaks

        Parameters
        ----------
        whois : GetLiveHistoricalOrReverseWhoisRequestWhois
            Type of WHOIS data to retrieve (e.g., live, historical, reverse)

        domain_name : typing.Optional[str]
            The domain name for retrieving live or historical WHOIS information. Note that reverse lookup does not support domain-based searches.

        keyword : typing.Optional[str]
            Keyword for reverse WHOIS lookup

        email : typing.Optional[str]
            Email address for reverse WHOIS lookup

        owner : typing.Optional[str]
            Owner name for reverse WHOIS lookup

        company : typing.Optional[str]
            Company name for reverse WHOIS lookup

        mode : typing.Optional[typing.Literal["mini"]]
            Mode for reverse WHOIS lookup (e.g., mini)

        page : typing.Optional[int]
            Page number for paginated results

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

        Returns
        -------
        typing.Dict[str, typing.Optional[typing.Any]]
            Successful response

        Examples
        --------
        from whoisfreaks import AsyncWhoisfreaksApi
        import asyncio
        client = AsyncWhoisfreaksApi()
        async def main() -> None:
            await client.get_live_historical_or_reverse_whois(whois="live", domain_name='whoisfreaks.com', keyword='whois', email='abc@xyz.com', owner='ejaz', company='jfreaks', )
        asyncio.run(main())
        """
        _response = await self._raw_client.get_live_historical_or_reverse_whois(
            whois=whois,
            domain_name=domain_name,
            keyword=keyword,
            email=email,
            owner=owner,
            company=company,
            mode=mode,
            page=page,
            request_options=request_options,
        )
        return _response.data

    async def get_dns_records(
        self,
        data_type: GetDnsRecordsRequestDataType,
        *,
        type: GetDnsRecordsRequestType,
        domain_name: typing.Optional[str] = None,
        value: typing.Optional[str] = None,
        page: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Dict[str, typing.Optional[typing.Any]]:
        """
        Retrieves live and historical records or dns data for a specified domain OR reverse DNS records for the specified data like IPV4 in case of A record and similarly for other supported records too.
        #ExamplePrompt Give me reverse DNS data for mx.zoho.com

        Parameters
        ----------
        data_type : GetDnsRecordsRequestDataType
            Type of DNS operation (live, historical, reverse)

        type : GetDnsRecordsRequestType
            Type of DNS records to retrieve. Possible values are [A, AAAA, NS, MX, CNAME, TXT, SPF, SOA, all]. When data_type is 'reverse', 'all' is not allowed.

        domain_name : typing.Optional[str]
            Domain name to retrieve DNS records for

        value : typing.Optional[str]
            Value to perform reverse DNS lookup on (e.g., IP address, domain name, etc.)

        page : typing.Optional[int]
            Page number for paginated results

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

        Returns
        -------
        typing.Dict[str, typing.Optional[typing.Any]]
            Successful response

        Examples
        --------
        from whoisfreaks import AsyncWhoisfreaksApi
        import asyncio
        client = AsyncWhoisfreaksApi()
        async def main() -> None:
            await client.get_dns_records(data_type="live", domain_name='whoisfreaks.com', value='8.8.8.8', type="A", )
        asyncio.run(main())
        """
        _response = await self._raw_client.get_dns_records(
            data_type, type=type, domain_name=domain_name, value=value, page=page, request_options=request_options
        )
        return _response.data

    async def get_live_ssl_certificate(
        self,
        *,
        domain_name: str,
        chain: typing.Optional[bool] = None,
        ssl_raw: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Dict[str, typing.Optional[typing.Any]]:
        """
        Retrieves live SSL certificate information for the specified domain.
        #ExamplePrompt When does whoisfreaks.com' SSL certificate will be expired?

        Parameters
        ----------
        domain_name : str
            Domain name to retrieve SSL certificate information for

        chain : typing.Optional[bool]
            Whether to include the certificate chain

        ssl_raw : typing.Optional[bool]
            Whether to include the raw SSL data

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

        Returns
        -------
        typing.Dict[str, typing.Optional[typing.Any]]
            Successful response

        Examples
        --------
        from whoisfreaks import AsyncWhoisfreaksApi
        import asyncio
        client = AsyncWhoisfreaksApi()
        async def main() -> None:
            await client.get_live_ssl_certificate(domain_name='whoisfreaks.com', )
        asyncio.run(main())
        """
        _response = await self._raw_client.get_live_ssl_certificate(
            domain_name=domain_name, chain=chain, ssl_raw=ssl_raw, request_options=request_options
        )
        return _response.data

    async def get_ip_whois(
        self, *, ip: str, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.Dict[str, typing.Optional[typing.Any]]:
        """
        Retrieves WHOIS information for the specified IP address.
        #ExamplePrompt give me WHOIS details of 8.8.8.8

        Parameters
        ----------
        ip : str
            IP address to retrieve WHOIS information for

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

        Returns
        -------
        typing.Dict[str, typing.Optional[typing.Any]]
            Successful response

        Examples
        --------
        from whoisfreaks import AsyncWhoisfreaksApi
        import asyncio
        client = AsyncWhoisfreaksApi()
        async def main() -> None:
            await client.get_ip_whois(ip='8.8.8.8', )
        asyncio.run(main())
        """
        _response = await self._raw_client.get_ip_whois(ip=ip, request_options=request_options)
        return _response.data

    async def get_asn_whois(
        self, *, asn: str, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.Dict[str, typing.Optional[typing.Any]]:
        """
        Retrieves WHOIS information for the specified ASN.
        #ExamplePrompt 'AS13335' AS number belongs to which organization?

        Parameters
        ----------
        asn : str
            ASN to retrieve WHOIS information for

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

        Returns
        -------
        typing.Dict[str, typing.Optional[typing.Any]]
            Successful response

        Examples
        --------
        from whoisfreaks import AsyncWhoisfreaksApi
        import asyncio
        client = AsyncWhoisfreaksApi()
        async def main() -> None:
            await client.get_asn_whois(asn='AS56554', )
        asyncio.run(main())
        """
        _response = await self._raw_client.get_asn_whois(asn=asn, request_options=request_options)
        return _response.data

    async def check_single_domain_availability(
        self,
        *,
        domain: str,
        sug: typing.Optional[bool] = None,
        count: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Dict[str, typing.Optional[typing.Any]]:
        """
        Checks the availability of the specified domain and provides suggestions if requested.
        #ExamplePrompt Is 'whoisfreaks.pk' a registered domain or not?

        Parameters
        ----------
        domain : str
            Domain to check availability for

        sug : typing.Optional[bool]
            Whether to provide domain suggestions

        count : typing.Optional[int]
            Number of suggestions to provide

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

        Returns
        -------
        typing.Dict[str, typing.Optional[typing.Any]]
            Successful response

        Examples
        --------
        from whoisfreaks import AsyncWhoisfreaksApi
        import asyncio
        client = AsyncWhoisfreaksApi()
        async def main() -> None:
            await client.check_single_domain_availability(domain='whoisfreaks.pk', )
        asyncio.run(main())
        """
        _response = await self._raw_client.check_single_domain_availability(
            domain=domain, sug=sug, count=count, request_options=request_options
        )
        return _response.data


def _get_base_url(*, base_url: typing.Optional[str] = None, environment: WhoisfreaksApiEnvironment) -> str:
    if base_url is not None:
        return base_url
    elif environment is not None:
        return environment.value
    else:
        raise Exception("Please pass in either base_url or environment to construct the client")
