/**
 * Flowtype definitions for fetchData
 * Generated by Flowgen from a Typescript Definition
 * Flowgen v1.21.0
 */

import { Api } from "@yoroi/types";
import { AxiosRequestConfig } from "axios";

declare module "axios" {
  declare interface AxiosRequestConfig {
    metadata?: {
      startTime: number,
      duration: number,
      ...
    };
  }
}

declare type FetcherHandlers = {
  onSuccess?: () => void,
  onError?: () => void,
  ...
};
declare type GetRequestConfig = {
  ...{
    url: string,
    method?: "get",
    headers?: { [key: string]: string, ... },
    ...
  },
  ...FetcherHandlers,
};
declare type OtherRequestConfig<D = any> = {
  ...{
    url: string,
    method: "post" | "put" | "delete",
    data?: D,
    headers?: { [key: string]: string, ... },
    ...
  },
  ...FetcherHandlers,
};
export type RequestConfig<D = any> = GetRequestConfig | OtherRequestConfig<D>;
export type FetchData = <T, D>(
  config: RequestConfig<D>,
  fetcherConfig?: AxiosRequestConfig<D>
) => Promise<Api.Response<T>>;
/**
 * Performs an HTTP request using Axios based on the specified configuration.
 * This function simplifies making HTTP requests by handling different
 * request methods and their respective data and headers.
 * @param config - The configuration object for the request.
 *   This includes the URL, HTTP method, optional data, and headers.
 *   The type of `config` varies based on the HTTP method:
 *   - For `GET` requests, `data` should not be provided.
 *   - For `POST`, `PUT`, and `DELETE` requests, `data` is optional.
 *   The config also includes optional success and error handlers:
 *   - `onSuccess`: Callback function called when the request succeeds
 *   - `onError`: Callback function called when the request fails
 * @note By default, all requests are configured with no-cache headers. If caching is needed,
 * you should provide custom headers in the config to override the default behavior.
 * @returns A `Promise` that resolves to the response data on a successful request
 * or an error object on failure. The error object includes the HTTP status
 * code and error message.
 * @template - The expected type of the response data.
 * @template - The type of the data to be sent with the request (for `POST`, `PUT`, `DELETE`).
 * @example ```typescript
 * // Example of a GET request with handlers
 * fetchData<{ someDataType }>({
 *   url: 'https://example.com/data',
 *   onSuccess: () => console.log('Request succeeded'),
 *   onError: () => console.log('Request failed'),
 * }).then(response => {
 *   // Handle response
 * }).catch(error => {
 *   // Handle error
 * })
 * ```
 * @example ```typescript
 * // Example of a POST request with data and handlers
 * fetchData<{ someDataType }, { somePayloadType }>({
 *   url: 'https://example.com/data',
 *   method: 'post',
 *   data: {...somePayload},
 *   onSuccess: () => console.log('Request succeeded'),
 *   onError: () => console.log('Request failed'),
 * }).then(response => {
 *   // Handle response
 * }).catch(error => {
 *   // Handle error
 * })
 * ```
 * @example ```typescript
 * // Example of a GET request with caching enabled
 * fetchData<{ someDataType }>({
 *   url: 'https://example.com/data',
 *   headers: {
 *     'Cache-Control': 'max-age=3600', // Cache for 1 hour
 *   },
 * }).then(response => {
 *   // Handle response
 * }).catch(error => {
 *   // Handle error
 * })
 * ```
 */
declare export var fetchData: FetchData;
