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

import typing

from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.request_options import RequestOptions
from .raw_client import AsyncRawDevelopersClient, RawDevelopersClient
from .types.create_free_key_developers_response import CreateFreeKeyDevelopersResponse
from .types.verify_free_key_developers_response import VerifyFreeKeyDevelopersResponse

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


class DevelopersClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawDevelopersClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawDevelopersClient
        """
        return self._raw_client

    def create_free_key(
        self, *, email: str, request_options: typing.Optional[RequestOptions] = None
    ) -> CreateFreeKeyDevelopersResponse:
        """
        Step 1 of 2: Request a verification code to get a free API key.

        - Sends a 6-digit code to your email (expires in 30 minutes)
        - Max 5 codes per email per hour (anti-spam)
        - If email already has a verified key, returns it immediately
        - Use POST /api/developers/keys/free/verify with the code to receive your key

        Parameters
        ----------
        email : str
            Your email address

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

        Returns
        -------
        CreateFreeKeyDevelopersResponse
            Verification code sent or existing key returned

        Examples
        --------
        from saferx import SafeRxClient

        client = SafeRxClient(
            api_key="YOUR_API_KEY",
        )
        client.developers.create_free_key(
            email="developer@example.com",
        )
        """
        _response = self._raw_client.create_free_key(email=email, request_options=request_options)
        return _response.data

    def verify_free_key(
        self, *, email: str, code: str, request_options: typing.Optional[RequestOptions] = None
    ) -> VerifyFreeKeyDevelopersResponse:
        """
        Step 2 of 2: Verify your email with the 6-digit code and receive your API key.

        - Code expires after 30 minutes
        - Max 5 wrong attempts per code (then must request new code)
        - On success: issues sfx_free_ key (persistent, 1 per email)
        - Free tier: 20 requests/minute, 60 requests/day

        Parameters
        ----------
        email : str
            The email you used in step 1

        code : str
            6-digit verification code from email

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

        Returns
        -------
        VerifyFreeKeyDevelopersResponse
            Email verified, API key issued

        Examples
        --------
        from saferx import SafeRxClient

        client = SafeRxClient(
            api_key="YOUR_API_KEY",
        )
        client.developers.verify_free_key(
            email="developer@example.com",
            code="123456",
        )
        """
        _response = self._raw_client.verify_free_key(email=email, code=code, request_options=request_options)
        return _response.data


class AsyncDevelopersClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawDevelopersClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawDevelopersClient
        """
        return self._raw_client

    async def create_free_key(
        self, *, email: str, request_options: typing.Optional[RequestOptions] = None
    ) -> CreateFreeKeyDevelopersResponse:
        """
        Step 1 of 2: Request a verification code to get a free API key.

        - Sends a 6-digit code to your email (expires in 30 minutes)
        - Max 5 codes per email per hour (anti-spam)
        - If email already has a verified key, returns it immediately
        - Use POST /api/developers/keys/free/verify with the code to receive your key

        Parameters
        ----------
        email : str
            Your email address

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

        Returns
        -------
        CreateFreeKeyDevelopersResponse
            Verification code sent or existing key returned

        Examples
        --------
        import asyncio

        from saferx import AsyncSafeRxClient

        client = AsyncSafeRxClient(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.developers.create_free_key(
                email="developer@example.com",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create_free_key(email=email, request_options=request_options)
        return _response.data

    async def verify_free_key(
        self, *, email: str, code: str, request_options: typing.Optional[RequestOptions] = None
    ) -> VerifyFreeKeyDevelopersResponse:
        """
        Step 2 of 2: Verify your email with the 6-digit code and receive your API key.

        - Code expires after 30 minutes
        - Max 5 wrong attempts per code (then must request new code)
        - On success: issues sfx_free_ key (persistent, 1 per email)
        - Free tier: 20 requests/minute, 60 requests/day

        Parameters
        ----------
        email : str
            The email you used in step 1

        code : str
            6-digit verification code from email

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

        Returns
        -------
        VerifyFreeKeyDevelopersResponse
            Email verified, API key issued

        Examples
        --------
        import asyncio

        from saferx import AsyncSafeRxClient

        client = AsyncSafeRxClient(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.developers.verify_free_key(
                email="developer@example.com",
                code="123456",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.verify_free_key(email=email, code=code, request_options=request_options)
        return _response.data
