# 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 ..types.attachments import Attachments
from ..types.email import Email
from ..types.idempotency_key import IdempotencyKey
from .raw_client import AsyncRawChargeBacksClient, RawChargeBacksClient
from .types.add_response_response import AddResponseResponse
from .types.chargeback_query_records import ChargebackQueryRecords

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


class ChargeBacksClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawChargeBacksClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawChargeBacksClient
        """
        return self._raw_client

    def add_response(
        self,
        id: int,
        *,
        idempotency_key: typing.Optional[IdempotencyKey] = None,
        attachments: typing.Optional[Attachments] = OMIT,
        contact_email: typing.Optional[Email] = OMIT,
        contact_name: typing.Optional[str] = OMIT,
        notes: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AddResponseResponse:
        """
        Add a response to a chargeback or ACH return.

        Parameters
        ----------
        id : int
            ID of the chargeback or return record.

        idempotency_key : typing.Optional[IdempotencyKey]

        attachments : typing.Optional[Attachments]
            Array of attached files to response.

        contact_email : typing.Optional[Email]
            Email of response submitter.

        contact_name : typing.Optional[str]
            Name of response submitter

        notes : typing.Optional[str]
            Response notes

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

        Returns
        -------
        AddResponseResponse
            Success

        Examples
        --------
        from payabli import payabli

        client = payabli(
            api_key="YOUR_API_KEY",
        )
        client.charge_backs.add_response(
            id=1000000,
            idempotency_key="6B29FC40-CA47-1067-B31D-00DD010662DA",
        )
        """
        _response = self._raw_client.add_response(
            id,
            idempotency_key=idempotency_key,
            attachments=attachments,
            contact_email=contact_email,
            contact_name=contact_name,
            notes=notes,
            request_options=request_options,
        )
        return _response.data

    def get_chargeback(
        self, id: int, *, request_options: typing.Optional[RequestOptions] = None
    ) -> ChargebackQueryRecords:
        """
        Retrieves a chargeback record and its details.

        Parameters
        ----------
        id : int
            ID of the chargeback or return record. This is returned as `chargebackId` in the [RecievedChargeback](/developers/developer-guides/webhook-payloads#receivedChargeback) and [ReceivedAchReturn](/developers/developer-guides/webhook-payloads#receivedachreturn) webhook notifications.

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

        Returns
        -------
        ChargebackQueryRecords
            Success

        Examples
        --------
        from payabli import payabli

        client = payabli(
            api_key="YOUR_API_KEY",
        )
        client.charge_backs.get_chargeback(
            id=1000000,
        )
        """
        _response = self._raw_client.get_chargeback(id, request_options=request_options)
        return _response.data

    def get_chargeback_attachment(
        self, file_name: str, id: int, *, request_options: typing.Optional[RequestOptions] = None
    ) -> str:
        """
        Parameters
        ----------
        file_name : str
            The chargeback attachment's file name.

        id : int
            The ID of chargeback or return record.

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

        Returns
        -------
        str
            OK

        Examples
        --------
        from payabli import payabli

        client = payabli(
            api_key="YOUR_API_KEY",
        )
        client.charge_backs.get_chargeback_attachment(
            file_name="fileName",
            id=1000000,
        )
        """
        _response = self._raw_client.get_chargeback_attachment(file_name, id, request_options=request_options)
        return _response.data


class AsyncChargeBacksClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawChargeBacksClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawChargeBacksClient
        """
        return self._raw_client

    async def add_response(
        self,
        id: int,
        *,
        idempotency_key: typing.Optional[IdempotencyKey] = None,
        attachments: typing.Optional[Attachments] = OMIT,
        contact_email: typing.Optional[Email] = OMIT,
        contact_name: typing.Optional[str] = OMIT,
        notes: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AddResponseResponse:
        """
        Add a response to a chargeback or ACH return.

        Parameters
        ----------
        id : int
            ID of the chargeback or return record.

        idempotency_key : typing.Optional[IdempotencyKey]

        attachments : typing.Optional[Attachments]
            Array of attached files to response.

        contact_email : typing.Optional[Email]
            Email of response submitter.

        contact_name : typing.Optional[str]
            Name of response submitter

        notes : typing.Optional[str]
            Response notes

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

        Returns
        -------
        AddResponseResponse
            Success

        Examples
        --------
        import asyncio

        from payabli import Asyncpayabli

        client = Asyncpayabli(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.charge_backs.add_response(
                id=1000000,
                idempotency_key="6B29FC40-CA47-1067-B31D-00DD010662DA",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.add_response(
            id,
            idempotency_key=idempotency_key,
            attachments=attachments,
            contact_email=contact_email,
            contact_name=contact_name,
            notes=notes,
            request_options=request_options,
        )
        return _response.data

    async def get_chargeback(
        self, id: int, *, request_options: typing.Optional[RequestOptions] = None
    ) -> ChargebackQueryRecords:
        """
        Retrieves a chargeback record and its details.

        Parameters
        ----------
        id : int
            ID of the chargeback or return record. This is returned as `chargebackId` in the [RecievedChargeback](/developers/developer-guides/webhook-payloads#receivedChargeback) and [ReceivedAchReturn](/developers/developer-guides/webhook-payloads#receivedachreturn) webhook notifications.

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

        Returns
        -------
        ChargebackQueryRecords
            Success

        Examples
        --------
        import asyncio

        from payabli import Asyncpayabli

        client = Asyncpayabli(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.charge_backs.get_chargeback(
                id=1000000,
            )


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

    async def get_chargeback_attachment(
        self, file_name: str, id: int, *, request_options: typing.Optional[RequestOptions] = None
    ) -> str:
        """
        Parameters
        ----------
        file_name : str
            The chargeback attachment's file name.

        id : int
            The ID of chargeback or return record.

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

        Returns
        -------
        str
            OK

        Examples
        --------
        import asyncio

        from payabli import Asyncpayabli

        client = Asyncpayabli(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.charge_backs.get_chargeback_attachment(
                file_name="fileName",
                id=1000000,
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get_chargeback_attachment(file_name, id, request_options=request_options)
        return _response.data
