import type { JSONSupport } from "../../core/JSONSupport.js";

export interface OrderByInfoProperties extends Partial<Pick<OrderByInfo, "field" | "order" | "valueExpression">> {}

/**
 * Class that allows you to define the drawing order of features in a [MapView](https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html).
 * Draw order can be defined by a number or date field value or an [Arcade expression](https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-support-OrderByInfo.html#valueExpression).
 *
 * @since 4.21
 * @example
 * // Draws features in the view so that features with larger population
 * // values are rendered on top of larger features.
 * const orderBy = new OrderByInfo({
 *   field: "POPULATION",
 *   order: "descending"
 * });
 *
 * layer.orderBy = [orderBy];
 */
export default class OrderByInfo extends JSONSupport {
  constructor(properties?: OrderByInfoProperties);
  /** The number or date field whose values will be used to sort features. */
  accessor field: string | null | undefined;
  /**
   * The sort order. If `ascending`, then features with smaller data values (they usually have
   * smaller symbols in size visualizations) will be drawn on top of features with larger data values.
   * If `descending`, then features with larger data values (usually larger symbols in size
   * visualizations) will be drawn on top of features with smaller data values. If date values are
   * used, then `ascending` means features with older values will be drawn on top of features with
   * more recent dates. A `descending` order for dates indicates features with more
   * recent values will be drawn on top of features with older values.
   *
   * @default "ascending"
   */
  accessor order: "ascending" | "descending";
  /**
   * An [Arcade](https://developers.arcgis.com/javascript/latest/arcade/) expression
   * following the specification defined by the [Arcade Feature Z Profile](https://developers.arcgis.com/javascript/latest/arcade/#feature-sorting).
   * Expressions may reference field values using the `$feature` profile variable and must return
   * a number or a date representing the z-value used to sort features.
   */
  accessor valueExpression: string | null | undefined;
  /**
   * Creates a deep clone of this object.
   *
   * @returns A deep clone of the
   * [OrderByInfo](https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-support-OrderByInfo.html) instance that
   * invoked this method.
   */
  clone(): OrderByInfo;
}