import { GatewayPlugin } from '@graphql-hive/gateway-runtime';
import { ExecutionRequest } from '@graphql-tools/utils';
import { MeshFetchRequestInit, Logger, ImportFn, MeshPlugin } from '@graphql-mesh/types';
import { PrometheusTracingPluginConfig, HistogramMetricOption, CounterMetricOption } from '@graphql-yoga/plugin-prometheus';
export { CounterAndLabels, FillLabelsFnParams, HistogramAndLabels, SummaryAndLabels, createCounter, createHistogram, createSummary } from '@graphql-yoga/plugin-prometheus';
import { Plugin } from 'graphql-yoga';
import { Registry } from 'prom-client';

interface TransportEntry<Options extends Record<string, any> = Record<string, any>> {
    kind: string;
    subgraph: string;
    location?: string;
    headers?: [string, string][];
    options?: Options;
}

type MeshMetricsConfig = {
    metrics: {
        /**
         * Tracks the duration of outgoing HTTP requests.
         * It reports the time spent on each request made using the `fetch` function provided by Mesh.
         * It is reported as an histogram.
         *
         * You can pass multiple type of values:
         *  - boolean: Disable or Enable the metric with default configuration
         *  - string: Enable the metric with custom name
         *  - number[]: Enable the metric with custom buckets
         *  - string[]: Enable the metric on a list of phases
         *  - ReturnType<typeof createHistogram>: Enable the metric with custom configuration
         */
        graphql_gateway_fetch_duration: HistogramMetricOption<'fetch', string, FetchMetricsLabelParams>;
        /**
         * Tracks the duration of subgraph execution.
         * It reports the time spent on each subgraph queries made to resolve incoming operations as an
         * histogram.
         *
         * You can pass multiple type of values:
         *  - boolean: Disable or Enable the metric with default configuration
         *  - string: Enable the metric with custom name
         *  - number[]: Enable the metric with custom buckets
         *  - string[]: Enable the metric on a list of phases
         *  - ReturnType<typeof createHistogram>: Enable the metric with custom configuration
         */
        graphql_gateway_subgraph_execute_duration: HistogramMetricOption<'subgraphExecute', string, SubgraphMetricsLabelParams>;
        /**
         * This metric tracks the number of errors that occurred during the subgraph execution.
         * It counts all errors found in the response returned by the subgraph execution.
         * It is exposed as a counter
         *
         * You can pass multiple type of values:
         *  - boolean: Disable or Enable the metric with default configuration
         *  - string: Enable the metric with custom name
         *  - number[]: Enable the metric with custom buckets
         *  - string[]: Enable the metric on a list of phases
         *  - ReturnType<typeof createHistogram>: Enable the metric with custom configuration
         */
        graphql_gateway_subgraph_execute_errors: CounterMetricOption<'subgraphExecute', string, SubgraphMetricsLabelParams>;
    };
    labels?: {
        /**
         * The name of the targeted subgraph.
         */
        subgraphName?: boolean;
        /**
         * The type of the GraphQL operation executed by the subgraph.
         *
         * The headers to include in the label can be specified as an array of strings.
         */
        fetchRequestHeaders?: boolean | string[];
        /**
         * The name of the GraphQL operation executed by the subgraph.
         *
         * The headers to include in the label can be specified as an array of strings.
         */
        fetchResponseHeaders?: boolean | string[];
    };
    /**
     * The logger instance used by the plugin to log messages.
     * This should be the logger instance provided by Mesh in the plugins context.
     */
    logger: Logger;
};
type PrometheusPluginOptions = PrometheusTracingPluginConfig & MeshMetricsConfig;
type YamlConfig = {
    baseDir?: string;
    importFn?: ImportFn;
    registry?: Registry | string;
};
type SubgraphMetricsLabelParams = {
    subgraphName: string;
    transportEntry?: TransportEntry;
    executionRequest: ExecutionRequest;
};
type FetchMetricsLabelParams = {
    url: string;
    options: MeshFetchRequestInit;
    response: Response;
};
declare function useMeshPrometheus(pluginOptions: Omit<PrometheusPluginOptions, 'registry'> & YamlConfig): MeshPlugin<any> & Plugin & GatewayPlugin;

export { type PrometheusPluginOptions, useMeshPrometheus as default };
