import type AttributeBinsGraphic from "@arcgis/core/AttributeBinsGraphic.js";
import type AttributeBinsFeatureSet from "@arcgis/core/rest/support/AttributeBinsFeatureSet.js";
import type { ErrorStrings } from "../../localization/interfaces.js";
import type { ChartSubType } from "../../misc/interfaces.js";
import type { QueryObject } from "../interfaces.js";
import type { AbortControllerKeyType, Features } from "./interfaces.js";
import type { WebChartQuery, WebChartTemporalBinning, WebHeatChart } from "../../../spec/web-chart.js";
import type { WebChartDataItem } from "../../../spec/data-source.js";
import type { ChartOptions } from "../../../chart-rendering/common/interfaces.js";

/**
 * Performs a query analytic.
 *
 * @param props - The object used to query (FL or FLV)
 * @internal
 */
export function queryAnalytic(props: {
    queryObject: QueryObject;
    queryConfig: WebChartQuery;
    outAnalytics: string;
    outputFormat: string;
    dataFormat: string;
}): Promise<WebChartDataItem | undefined>;

/**
 * Generates the aliases to use in the queryAttributeBins query to name the stacks and boundaries for the x field
 *
 * @param x - The x field used for the stack alias
 * @param y - The y field used by the stacks
 * @internal
 */
export function getQueryAttributeBinsForScatterplotFieldsAlias(x: string, y: string): {
    lowerBoundaryAlias: string;
    upperBoundaryAlias: string;
    stackAlias: string;
};

/**
 * Fetches and returns the heat chart data using query(Attribute)Bins
 *
 * @param props - The chart configuration
 * @internal
 */
export function queryAttributeBinsForHeatChart(props: {
    chartConfig: WebHeatChart;
    queryObject: QueryObject;
    queryConfig: WebChartQuery;
    options?: ChartOptions;
    errorStrings: ErrorStrings;
}): Promise<AttributeBinsFeatureSet | undefined>;

/**
 * Query the features for the matrix heat chart.
 *
 * @param props - The chart configuration
 * @internal
 */
export function queryFeaturesForMatrixHeatChart(props: {
    chartConfig: WebHeatChart;
    queryObject: QueryObject;
    queryConfig: WebChartQuery;
    returnFeaturesExtent?: boolean;
    errorStrings: ErrorStrings;
    abortKey?: AbortControllerKeyType;
}): Promise<Features | undefined>;

/**
 * Uses query(Attribute)Bins to fetch the aggregated scatterplot data
 *
 * @param props - The object used to query (FL or FLV)
 * @internal
 */
export function queryAttributeBinsForScatterplot(props: {
    queryObject: QueryObject;
    queryConfig: WebChartQuery;
    xStep: number;
    yStep: number;
    xMin: number;
    xMax: number;
    x: string;
    y: string;
    errorStrings: ErrorStrings;
}): Promise<AttributeBinsFeatureSet | undefined>;

/**
 * Performs a query feature count based on the provided parameters.
 *
 * @param props - The object used to query (FL or FLV)
 * @internal
 */
export function queryFeatureCount(props: {
    queryObject: QueryObject;
    queryConfig: WebChartQuery;
    chartSubType: ChartSubType;
    x: string;
    isGaugeByFeature?: boolean;
}): Promise<number | undefined>;

/**
 * Fetches multiple statistics (min, max, count...).
 * Returns an object mapping the outStatisticFieldName with its value
 *
 * @param props - The object used to query (FL or FLV)
 * @internal
 */
export function queryStatistics<T extends Date | number | string>(props: {
    queryObject: QueryObject;
    queryConfig: WebChartQuery;
    abortKey?: AbortControllerKeyType;
}): Promise<Map<string, T>>;

/**
 * @param props
 * @internal
 */
export function queryFeatures(props: {
    queryObject?: QueryObject;
    queryConfig?: WebChartQuery;
    returnUniqueIdsOnly?: boolean;
    abortKey?: AbortControllerKeyType;
}): Promise<Features>;

/**
 * Fetches all the features from the input QueryObject, according to the other specified input settings (query, outFields...).
 * Handles the paging.
 *
 * @param props - The object used to query (FL or FLV)
 * @internal
 */
export function queryAllFeatures(props: {
    queryObject?: QueryObject;
    queryConfig?: WebChartQuery;
    returnUniqueIdsOnly?: boolean;
    featureCount?: number;
    noBatch?: boolean;
    abortKey?: AbortControllerKeyType;
}): Promise<Features>;

/**
 * Fetches the extent of all the features that are represented by their object ids
 *
 * @param props - The object used to query (FL or FLV)
 * @internal
 */
export function queryUniqueIDs(props: {
    queryObject?: QueryObject;
    queryConfig: WebChartQuery;
    uniqueFeature?: boolean;
    abortKey?: AbortControllerKeyType;
}): Promise<(number | string)[]>;

/**
 * Aborts all existing queries and initializes a controller for new ones. The queries are associated
 * to a unique key to avoid cancelling queries for other charts.
 *
 * @param key - The key pointing to the abort controller to execute
 * @internal
 */
export function abortPendingQueries(key?: AbortControllerKeyType): void;

/**
 * @param x
 * @internal
 */
export function getQueryAttributeBinsForTemporalDataAliases(x: string): {
    lowerBoundaryAlias: string;
    upperBoundaryAlias: string;
};

/**
 * Fetches binned temporal data using queryAttributeBins().
 * TODO: support for offset
 * TODO: support for abortKey input parameter
 *
 * @param props - The object used to query (FL or FLV)
 * @internal
 */
export function queryAttributeBinsForTemporalData(props: {
    queryObject?: QueryObject;
    queryConfig: WebChartQuery;
    temporalBinning?: WebChartTemporalBinning;
    dateField: string;
    splitByField?: string;
    abortKey?: AbortControllerKeyType;
}): Promise<AttributeBinsGraphic[]>;