import type Extent from "../../geometry/Extent.js";
import type Multipoint from "../../geometry/Multipoint.js";
import type Point from "../../geometry/Point.js";
import type Polyline from "../../geometry/Polyline.js";
import type SpatialReference from "../../geometry/SpatialReference.js";
import type { EventedAccessor } from "../../core/Evented.js";

/**
 * A cache of elevation values created from an elevation service or the [GroundView](https://developers.arcgis.com/javascript/latest/api-reference/esri-views-GroundView.html)
 * used for synchronously querying elevation information for geometries.
 * This class does not have a constructor. You can create an instance of this class by using
 * [ElevationLayer#createElevationSampler()](https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-ElevationLayer.html#createElevationSampler)
 * or [Ground#createElevationSampler()](https://developers.arcgis.com/javascript/latest/api-reference/esri-Ground.html#createElevationSampler) methods.
 * The elevation sampler created from the [Ground](https://developers.arcgis.com/javascript/latest/api-reference/esri-Ground.html) will sample data from the first elevation layer that has data available.
 * To control the layer used for elevation sampling and the sampling resolution, use
 * [ElevationLayer#createElevationSampler()](https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-ElevationLayer.html#createElevationSampler).
 *
 * ```js
 * map.ground.load()
 *   .then(function() {
 *     // create an elevation sampler from a given extent
 *     return view.map.ground.createElevationSampler(extent);
 *   })
 *   .then(function(elevationSampler) {
 *     // use the elevation sampler to get z-values for a point, multipoint or polyline geometry
 *     let zEnrichedGeometry = elevationSampler.queryElevation(geometry);
 *   });
 * ```
 *
 * An instance of this class is also available in [GroundView#elevationSampler](https://developers.arcgis.com/javascript/latest/api-reference/esri-views-GroundView.html#elevationSampler).
 * This can be used when the elevation values need to reflect the elevation currently displayed in the view.
 *
 * ```js
 * let elevationSampler = view.groundView.elevationSampler;
 * // listen for elevation changes in the view
 * elevationSampler.on('changed', function() {
 *   // enrich geometry with z-values from the elevation displayed in the view
 *   let zEnrichedGeometry = elevationSampler.queryElevation(point);
 * });
 * ```
 *
 * @since 4.7
 * @see [ElevationLayer#createElevationSampler()](https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-ElevationLayer.html#createElevationSampler)
 * @see [Ground#createElevationSampler()](https://developers.arcgis.com/javascript/latest/api-reference/esri-Ground.html#createElevationSampler)
 * @see [GroundView#elevationSampler](https://developers.arcgis.com/javascript/latest/api-reference/esri-views-GroundView.html#elevationSampler)
 */
export default abstract class ElevationSampler extends EventedAccessor {
  /**
   * @deprecated
   * Do not directly reference this property.
   * Use EventNames and EventTypes helpers from \@arcgis/core/Evented
   */
  "@eventTypes": ElevationSamplerEvents;
  /** The minimum and maximum resolution of the data in the sampler. */
  abstract readonly demResolution: ElevationSamplerDemResolutionRange;
  /**
   * The extent within which the sampler can be queried.
   *
   * @since 4.9
   */
  abstract readonly extent?: Extent | null;
  /**
   * The value that is used to represent areas where there is no data available.
   *
   * @since 4.9
   */
  abstract readonly noDataValue?: number | null;
  /**
   * The spatial reference of the sampler.
   *
   * @since 4.24
   */
  abstract readonly spatialReference: SpatialReference;
  /**
   * Get elevation for a coordinate specified in the spatial reference of the sampler. This is typically faster
   * than [queryElevation()](https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-support-ElevationSampler.html#queryElevation) when getting elevation for many
   * coordinates that are guaranteed to be in the spatial reference of the sampler. If the coordinate is outside
   * of the elevation sampler extent, then the samplers [noDataValue](https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-support-ElevationSampler.html#noDataValue)
   * will be returned.
   *
   * @param x - The x coordinate.
   * @param y - The y coordinate.
   * @returns the elevation at the provided location. If no data could be sampled at the location, then the
   *   samplers [noDataValue](https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-support-ElevationSampler.html#noDataValue) will be returned.
   * @since 4.24
   */
  abstract elevationAt(x: number, y: number): number;
  /**
   * Query elevation for a [Point](https://developers.arcgis.com/javascript/latest/api-reference/esri-geometry-Point.html), [Polyline](https://developers.arcgis.com/javascript/latest/api-reference/esri-geometry-Polyline.html) or
   * [Multipoint](https://developers.arcgis.com/javascript/latest/api-reference/esri-geometry-Multipoint.html) geometry. A query will return a new geometry
   * for which the z-values for each coordinate in the geometry are obtained from the elevation
   * sampler. If the geometry used for the query is outside of the elevation sampler extent,
   * then the returned geometry has the samplers [noDataValue](https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-support-ElevationSampler.html#noDataValue)
   * as z-values.
   *
   * @param geometry - The geometry to use for sampling elevation data.
   * @returns The sampled geometry.
   */
  queryElevation(geometry: Point | Polyline | Multipoint): Point | Polyline | Multipoint | null | undefined;
}

export interface ElevationSamplerEvents {
  /**
   * Fires when the data in the sampler has changed. This event is only relevant for dynamic elevation samplers
   * such as the elevation sampler on the [GroundView](https://developers.arcgis.com/javascript/latest/api-reference/esri-views-GroundView.html).
   *
   * @example
   * view.groundView.elevationSampler.on("changed", function(evt) {
   *  console.log("elevation has changed");
   * });
   */
  changed: Record<never, never>;
}

export interface ElevationSamplerDemResolutionRange {
  /** The maximum resolution. */
  max: number;
  /** The minimum resolution. */
  min: number;
}