/**
 * This object contains helper methods for generating class breaks visualizations for raster layers (i.e. [ImageryLayer](https://developers.arcgis.com/javascript/latest/references/core/layers/ImageryLayer/), [ImageryTileLayer](https://developers.arcgis.com/javascript/latest/references/core/layers/ImageryTileLayer/), or [WCSLayer](https://developers.arcgis.com/javascript/latest/references/core/layers/WCSLayer/)) based on a cell or field value.
 *
 * The [createRenderer()](https://developers.arcgis.com/javascript/latest/references/core/smartMapping/raster/renderers/classBreaks/#createRenderer) method in this module generates a renderer that may be applied directly to the input layer.
 *
 * @since 4.20
 */
import type ClassBreaksRenderer from "../../../renderers/ClassBreaksRenderer.js";
import type AlgorithmicColorRamp from "../../../rest/support/AlgorithmicColorRamp.js";
import type MultipartColorRamp from "../../../rest/support/MultipartColorRamp.js";
import type { ClassificationMethod } from "../../../renderers/types.js";
import type { RasterRendererParameters } from "./types.js";
import type { ClassBreaksResult } from "../../statistics/types.js";

export interface RasterClassBreaksRendererParameters extends RasterRendererParameters {
  /**
   * The color ramp to apply to the renderer.
   *
   * @since 5.0
   */
  colorRamp?: AlgorithmicColorRamp | MultipartColorRamp;
  /**
   * The colors to apply to each class break. This must be a
   *   two-dimensional array where each item of the first dimension is an array of 3-4 numbers representing
   *   the RGB or RGBA values of each class break.  This overrides `colorRamp`.
   *
   * @since 5.0
   */
  colors?: number[][];
  /**
   * The field whose data will be used in the classification.
   *
   * @default value
   * @since 5.0
   */
  field?: string;
  /**
   * The number of class breaks to generate for the classification. This is ignored if a `standard-deviation` classification method is specified.
   *
   * @default 5
   * @since 5.0
   */
  numClasses?: number;
  /**
   * The classification method used for generating breaks.
   *
   * @default natural-breaks
   * @since 5.0
   */
  classificationMethod?: Exclude<ClassificationMethod, "manual">;
  /**
   * Only applicable when `classificationMethod` is `defined-interval`. Specifies the interval of each break.
   *   Note this may cause the last break to extend beyond the actual data max.
   *
   * @since 5.0
   */
  definedInterval?: number;
}

/**
 * The result object of the [createRenderer()](https://developers.arcgis.com/javascript/latest/references/core/smartMapping/raster/renderers/classBreaks/#createRenderer) method. See the table
 * below for details of each property.
 */
export interface RasterClassBreaksResult {
  /**
   * The renderer object configured to best
   * match the given basemap and the spread of the data. Set this on a layer's `renderer` property to
   * update its visualization.
   */
  renderer: ClassBreaksRenderer;
  /**
   * This object
   * describes class breaks generated from data in a layer for a given field with a specified classification method.
   */
  classBreaksResult: ClassBreaksResult;
}

/**
 * Generates a [ClassBreaksRenderer](https://developers.arcgis.com/javascript/latest/references/core/renderers/ClassBreaksRenderer/) used to render imagery data.
 * Depending on the `classificationMethod`, class breaks (or data ranges) are generated based on the statistics of the data.
 * Each cell is assigned a color based on the class break in which the value of the cell or `field` falls.
 *
 * @param parameters - Input parameters for generating a classed color visualization for raster data
 * returned from the cell value or a given field.
 * @returns Resolves with
 *   an object containing a ClassBreaksRenderer that can be set on the input layer.
 */
export function createRenderer(parameters: RasterClassBreaksRendererParameters): Promise<RasterClassBreaksResult>;