import type LengthDimension from "../../analysis/LengthDimension.js";
import type DimensionLayer from "../../layers/DimensionLayer.js";
import type LengthDimensionResult from "../analysis/LengthDimensionResult.js";
import type LayerView from "./LayerView.js";
import type { ReadonlyCollection } from "../../core/Collection.js";
import type { AbortOptions } from "../../core/promiseUtils.js";
import type { DimensionPlacementResult } from "../3d/analysis/Dimension/types.js";
import type { LayerViewProperties } from "./LayerView.js";

export interface DimensionLayerViewProperties extends LayerViewProperties, Partial<Pick<DimensionLayerView, "interactive" | "selectedDimension">> {}

/**
 * Represents the [LayerView](https://developers.arcgis.com/javascript/latest/references/core/views/layers/LayerView/) of a [DimensionLayer](https://developers.arcgis.com/javascript/latest/references/core/layers/DimensionLayer/)
 * after it has been added to a [Map](https://developers.arcgis.com/javascript/latest/references/core/Map/) in a [SceneView](https://developers.arcgis.com/javascript/latest/references/core/views/SceneView/).
 *
 * The dimension layer view controls whether the dimensions in its associated
 * [DimensionLayer.source](https://developers.arcgis.com/javascript/latest/references/core/layers/DimensionLayer/#source) can be created or edited interactively.
 *
 * It allows to create new dimensions interactively using the [place()](https://developers.arcgis.com/javascript/latest/references/core/views/layers/DimensionLayerView/#place) method, query measured [results](https://developers.arcgis.com/javascript/latest/references/core/views/layers/DimensionLayerView/#results),
 * or to make existing dimensions selectable and editable by enabling the [interactive](https://developers.arcgis.com/javascript/latest/references/core/views/layers/DimensionLayerView/#interactive) property.
 * To select a dimension, hover and click on its offset manipulator.
 *
 * The view for the layer can be retrieved using [SceneView.whenLayerView()](https://developers.arcgis.com/javascript/latest/references/core/views/SceneView/#whenLayerView).
 *
 * ```js
 * // create new layer and add it to the map
 * const dimensionLayer = new DimensionLayer();
 * view.map.add(dimensionLayer);
 *
 * // retrieve layer view for the layer
 * const dimensionLayerView = await view.whenLayerView(dimensionLayer);
 * ```
 *
 * > [!WARNING]
 * >
 * > **Things to consider:**
 * > Snapping is enabled by default. This can be temporarily disabled by holding the `CTRL` key.
 * > Layer types currently supported for snapping are: [FeatureLayer](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/), [GraphicsLayer](https://developers.arcgis.com/javascript/latest/references/core/layers/GraphicsLayer/) (except Mesh geometries),
 * > [GeoJSONLayer](https://developers.arcgis.com/javascript/latest/references/core/layers/GeoJSONLayer/), [WFSLayer](https://developers.arcgis.com/javascript/latest/references/core/layers/WFSLayer/), [CSVLayer](https://developers.arcgis.com/javascript/latest/references/core/layers/CSVLayer/),
 * > [3D Object SceneLayer](https://developers.arcgis.com/javascript/latest/references/core/layers/SceneLayer/), and [BuildingSceneLayer](https://developers.arcgis.com/javascript/latest/references/core/layers/BuildingSceneLayer/).
 *
 * @since 4.25
 * @see [DimensionLayer](https://developers.arcgis.com/javascript/latest/references/core/layers/DimensionLayer/)
 * @see [DimensionAnalysis](https://developers.arcgis.com/javascript/latest/references/core/analysis/DimensionAnalysis/)
 * @see [LengthDimension](https://developers.arcgis.com/javascript/latest/references/core/analysis/LengthDimension/)
 * @see [DimensionSimpleStyle](https://developers.arcgis.com/javascript/latest/references/core/analysis/DimensionSimpleStyle/)
 * @see [DimensionAnalysisView3D](https://developers.arcgis.com/javascript/latest/references/core/views/3d/analysis/DimensionAnalysisView3D/)
 * @see [Sample - Length dimensioning](https://developers.arcgis.com/javascript/latest/sample-code/layers-dimension/)
 */
export default abstract class DimensionLayerView extends LayerView {
  /**
   * Enables interactivity for the [layer](https://developers.arcgis.com/javascript/latest/references/core/views/layers/DimensionLayerView/#layer). When set to `true` and the layer's
   * [DimensionLayer.source](https://developers.arcgis.com/javascript/latest/references/core/layers/DimensionLayer/#source) includes any
   * valid [DimensionAnalysis.dimensions](https://developers.arcgis.com/javascript/latest/references/core/analysis/DimensionAnalysis/#dimensions), they become selectable and editable.
   *
   * @default false
   */
  accessor interactive: boolean;
  /** The layer this layer view represents. */
  get layer(): DimensionLayer;
  /**
   * Results for each dimension in the layer [DimensionLayer.source](https://developers.arcgis.com/javascript/latest/references/core/layers/DimensionLayer/#source).
   *
   * Given a [dimension](https://developers.arcgis.com/javascript/latest/references/core/analysis/LengthDimension/) object, the results collection can be searched:
   *
   * ```js
   * const result = dimensionLayerView.results.find((result) => result.dimension === dimensionObject);
   * ```
   */
  get results(): ReadonlyCollection<LengthDimensionResult>;
  /**
   * The selected dimension. If [interactive](https://developers.arcgis.com/javascript/latest/references/core/views/layers/DimensionLayerView/#interactive) is `true`, any dimension in the
   * [layer](https://developers.arcgis.com/javascript/latest/references/core/views/layers/DimensionLayerView/#layer) can be selected by clicking on it in the view. As long as [interactive](https://developers.arcgis.com/javascript/latest/references/core/views/layers/DimensionLayerView/#interactive)
   * remains `true`, the properties of the selected dimension can be edited by interacting with
   * manipulators in the view.
   */
  accessor selectedDimension: LengthDimension | null | undefined;
  /**
   * Starts the interactive creation of new dimensions and adds them to the [layer](https://developers.arcgis.com/javascript/latest/references/core/views/layers/DimensionLayerView/#layer)'s
   * [DimensionLayer.source](https://developers.arcgis.com/javascript/latest/references/core/layers/DimensionLayer/#source).
   *
   * The creation process will finish when the user double-clicks the mouse or presses the escape key.
   * To stop the creation programmatically, pass an abort signal as an argument when calling the method.
   *
   * This method is similar to the [place()](https://developers.arcgis.com/javascript/latest/references/core/views/layers/DimensionLayerView/#place) method, but it allows to create multiple dimensions in a row.
   *
   * Calling this method sets [interactive](https://developers.arcgis.com/javascript/latest/references/core/views/layers/DimensionLayerView/#interactive) to `true`.
   *
   * @param options - An object specifying additional options.
   * @returns A promise which resolves when creation is completed successfully or rejected if it is
   * canceled.
   * @example
   * const abortController = new AbortController();
   *
   * try {
   *   await layerView.createLengthDimensions({ signal: abortController.signal });
   * } catch (error) {
   *   if (error.name === "AbortError") {
   *     console.log("Creation operation was cancelled.");
   *   }
   * }
   *
   * // cancel the placement operation at some later point
   * abortController.abort();
   */
  createLengthDimensions(options?: AbortOptions | null | undefined): Promise<void>;
  /**
   * Starts the interactive placement of a single dimension, adding it to the [layer](https://developers.arcgis.com/javascript/latest/references/core/views/layers/DimensionLayerView/#layer)'s
   * [DimensionLayer.source](https://developers.arcgis.com/javascript/latest/references/core/layers/DimensionLayer/#source).
   *
   * The first click places start point and the second sets end point.
   *
   * The placement operation will finish when the user presses the escape key.
   * To stop the placing programmatically, pass an abort signal as an argument when calling the method.
   *
   * Calling this method sets [interactive](https://developers.arcgis.com/javascript/latest/references/core/views/layers/DimensionLayerView/#interactive) to `true`.
   *
   * @param options - An object specifying additional options.
   * @returns A promise which
   * resolves when the operation is completed successfully or rejected if it is canceled.
   * @since 4.33
   * @example
   * const abortController = new AbortController();
   *
   * try {
   *   await layerView.place({ signal: abortController.signal });
   * } catch (error) {
   *   if (error.name === "AbortError") {
   *     console.log("Placement operation was cancelled.");
   *   }
   * }
   *
   * // cancel the placement operation at some later point
   * abortController.abort();
   */
  place(options?: AbortOptions | null | undefined): Promise<DimensionPlacementResult>;
}