import type Ajv from "ajv";
import type { ErrorKeywords } from "../../errors/interfaces.js";
import type { RESTFieldType } from "../../../spec/rest-js-object-literals.js";
import type { WebChartStatisticType } from "../../../spec/chart-object-literals.js";

/** @internal */
export const ConfigWarningKeywords: {
    readonly NonNumericAggregation: "nonNumericAggregation";
    readonly DuplicateSeriesID: "duplicateSeriesId";
};

/** @internal */
export type ConfigWarningKeywords = (typeof ConfigWarningKeywords)[keyof typeof ConfigWarningKeywords];

/** @internal */
export interface ConfigWarningObject {
  keyword: ConfigWarningKeywords;
  dataPath: string;
  message: string;
  params: DuplicateSeriesIdParams | NumericAggregationParams;
}

/** @internal */
export interface CustomErrorObject {
  keyword: ErrorKeywords;
  message: string;
  params: LayerLoadFailureParams | string;
}

/**
 * Validation Status interface which described the validity of the input WebChart config
 *
 * @internal
 */
export interface ValidationStatus {
  valid: boolean;
  schemaErrors: Ajv.ErrorObject[];
  customErrors: CustomErrorObject[];
  warnings: ConfigWarningObject[];
}

/** @internal */
export const ConfigErrorKeywords: {
    readonly Required: "required";
    readonly MinLength: "minLength";
    readonly MinItems: "minItems";
    readonly MaxItems: "maxItems";
    readonly Pattern: "pattern";
    readonly AdditionalProperties: "additionalProperties";
    readonly Enum: "enum";
    readonly AnyOf: "anyOf";
};

/** @internal */
export const DataWarningKeywords: {
    readonly BadData: "badData";
    readonly EmptyDataSet: "emptyDataSet";
    readonly InvalidConfig: "invalidConfig";
    readonly HistogramEmptyField: "histogramEmptyField";
    readonly BarElementExceedsLimit: "barElementExceedsLimit";
    readonly LineChartExceedsLimit: "lineChartExceedsLimit";
    readonly BoxPlotExceedsLimit: "boxPlotExceedsLimit";
    readonly BoxPlotOutliersExceedsLimit: "boxPlotOutliersExceedsLimit";
    readonly HeatChartExceedsLimit: "heatChartExceedsLimit";
    readonly PieChartExceedsLimit: "pieChartExceedsLimit";
    readonly GaugeExceedsLimit: "gaugeExceedsLimit";
    readonly PieChartMixOfNegativePositiveSlices: "PieChartMixOfNegativePositiveSlices";
    readonly NegativeValueInSqrtCalculation: "negativeValueInSqrtCalculation";
    readonly NegativeValueInLogCalculation: "negativeValueInLogCalculation";
    readonly NegativeValueInXAxisLogScale: "negativeValueInXAxisLogScale";
    readonly NegativeValueInYAxisLogScale: "negativeValueInYAxisLogScale";
};

export type DataWarningKeywords = (typeof DataWarningKeywords)[keyof typeof DataWarningKeywords];

/** @internal */
export interface ElementCountExceededParams {
  actualCount: number;
  totalLimit: number;
  seriesLimit?: number;
}

/** @internal */
export interface DataWarningObject {
  keyword: DataWarningKeywords;
  header: string;
  message: string;
  params?: ElementCountExceededParams;
}

export interface NumericAggregationParams {
  fieldName: string;
  fieldType: RESTFieldType;
  aggregationRequested: WebChartStatisticType;
}

export interface DuplicateSeriesIdParams {
  seriesName: string;
  seriesId: string;
}

export interface LayerLoadFailureParams {
  url: string;
  portalItemId: string;
}