import type { BaseRasterFunctionParameters } from "../types.js";
import type { RasterBandStatistics } from "../../../support/types.js";

export type KebabConvolutionTypes = "user-defined" | "line-detection-horizontal" | "line-detection-vertical" | "line-detection-left-diagonal" | "line-detection-right-diagonal" | "gradient-north" | "gradient-west" | "gradient-east" | "gradient-south" | "gradient-north-east" | "gradient-north-west" | "smooth-arithmetic-mean" | "smoothing3x3" | "smoothing5x5" | "sharpening3x3" | "sharpening5x5" | "laplacian3x3" | "laplacian5x5" | "sobel-horizontal" | "sobel-vertical" | "sharpen" | "sharpen2" | "point-spread" | "none";

/** @since 4.28 */
export interface ConvolutionFunctionParameters extends BaseRasterFunctionParameters {
  /** The convolution type. */
  convolutionType: Exclude<KebabConvolutionTypes, "user-defined">;
}

/** @since 4.28 */
export interface ConvolutionFunctionCustomParameters extends BaseRasterFunctionParameters {
  /** The number of columns, only needed for user-defined kernel */
  cols: number;
  /** The convolution type must be "user-defined". */
  convolutionType?: "user-defined";
  /** The kernel size of rows x columns arranged in row-major order. */
  kernel: number[];
  /** The number of rows, only needed for user-defined kernel. */
  rows: number;
}

/**
 * ***********************************************
 *
 *                 contrastBrightness
 */
export interface ContrastBrightnessParameters extends BaseRasterFunctionParameters {
  /** Brightness offset from -100 to 100. */
  brightnessOffset: number;
  /** Contrast offset from -100 to 100. */
  contrastOffset: number;
}

export interface BaseStretchParameters extends BaseRasterFunctionParameters {
  /** When true, perform dynamic range adjustment (not supported on client side) */
  dynamicRangeAdjustment?: boolean;
  /** The gamma values used for each band, needed when useGamma is true. */
  gamma?: number[];
  /** The maximum output value. Default is 255. */
  outputMax?: number;
  /** The minimum output value. Default is 0. */
  outputMin?: number;
  /** When true, gamma stretch is applied. */
  useGamma?: boolean;
}

export interface MinMaxStretchParameters extends BaseStretchParameters {
  /**
   * The avg and stddev in each band's statistics
   * is used along with numberOfStandardDeviations to calculate the cut off pixels values beling stretched. Default is the input data source's statistics.
   */
  statistics?: RasterBandStatistics[];
}

export interface StddevStretchParameters extends MinMaxStretchParameters {
  /**
   * Values with in the given number of standard deviations are stretched to
   * [outputMin, outputMax], those fall outside are clamped.
   */
  numberOfStandardDeviations?: number;
}

export interface PercentClipStretchParameters extends BaseStretchParameters {
  /** Percentage of the highest pixel values to be excluded. */
  maxPercent?: number;
  /** Percentage of the lowest pixel values to be excluded. */
  minPercent?: number;
}