import type Graphic from "../../Graphic.js";
import type Collection from "../../core/Collection.js";
import type SelectionManager from "../SelectionManager.js";
import type { EventedAccessor } from "../../core/Evented.js";
import type { DrawingMode } from "../draw/types.js";
import type { SelectableViewUnion, SelectionOperationCreateTool, SelectionOperationType, SelectionSource, SelectionToolName } from "./types.js";

/**
 * Construction properties for a selection operation.
 *
 * @since 5.1
 */
export interface SelectionOperationProperties extends Partial<Pick<SelectionOperation, "persistSelection" | "returnFeatureTitleFields" | "returnGeometry" | "sources" | "type">> {
  /**
   * The type of drawing tool being used by this selection operation.
   *
   * @default "rectangle"
   * @since 5.1
   */
  createTool?: SelectionOperationCreateTool;
  /**
   * Indicates the draw mode being used by this selection operation.
   *
   * @since 5.1
   */
  mode?: DrawingMode | null;
  /**
   * A reference to a custom [selection manager](https://developers.arcgis.com/javascript/latest/references/core/views/SelectionManager/). Otherwise, the selection operation
   * uses the selection manager on the provided view.
   *
   * @since 5.1
   */
  selectionManager?: SelectionManager | null;
  /**
   * Indicates whether the selection operation should only update the selection when the operation
   * successfully completes, rather than while actively drawing.
   *
   * @default true
   * @since 5.1
   */
  selectOnComplete?: boolean;
  /**
   * Reference to the current drawing tool being used by the selection operation.
   *
   * @default ""
   * @since 5.1
   */
  toolName?: SelectionToolName;
  /**
   * Reference to the view being used by the selection operation.
   *
   * @since 5.1
   */
  view?: SelectableViewUnion;
}

/**
 * The selection operation is responsible for creating and using an interactive drawing tool to maintain
 * an interactively updated graphics selection set while a selection area is being drawn. The interactive
 * tool is active on the view when the operation is created. After the operation is completed (selection area
 * is finalized or cancelled), the interactive tool is removed. Each operation can only be used once and
 * a new selection operation should be created each time a new selection is required.
 *
 * @since 5.1
 */
export default class SelectionOperation extends EventedAccessor {
  /** @since 5.1 */
  constructor(properties: SelectionOperationProperties);
  /**
   * Indicates whether the selection operation has been completed or cancelled.
   *
   * @since 5.1
   */
  get completed(): boolean;
  /**
   * The type of drawing tool being used by this selection operation.
   *
   * @default "rectangle"
   * @since 5.1
   */
  get createTool(): SelectionOperationCreateTool;
  /**
   * The selection manager being used by this selection operation.
   *
   * @since 5.1
   */
  get effectiveSelectionManager(): SelectionManager;
  /**
   * The current effective type of the selection operation. Accounts for modifications
   * to the active type when holding a constraint key (Control or Meta).
   *
   * @since 5.1
   */
  get effectiveType(): SelectionOperationType;
  /**
   * Indicates the draw mode being used by this selection operation.
   *
   * @since 5.1
   */
  get mode(): DrawingMode | null | undefined;
  /**
   * Indicates whether the selection operation will persist the determined selection via the
   * current effective selection manager.
   *
   * @default true
   * @since 5.1
   */
  accessor persistSelection: boolean;
  /**
   * Indicates whether the selection operation is determining the final selection set.
   *
   * @since 5.1
   */
  get processingFinalSelection(): boolean;
  /**
   * Indicates whether the selection operation should return [graphics](https://developers.arcgis.com/javascript/latest/references/core/Graphic/) with attributes
   * required to determine a title for individual selected features.
   *
   * @default false
   * @since 5.1
   */
  accessor returnFeatureTitleFields: boolean;
  /**
   * Indicates whether the selection operation should return [graphics](https://developers.arcgis.com/javascript/latest/references/core/Graphic/) with
   * geometries when determining the selection.
   *
   * @default true
   * @since 5.1
   */
  accessor returnGeometry: boolean;
  /**
   * A reference to the current working selection while actively drawing.
   *
   * @since 5.1
   */
  get selection(): Collection<Graphic>;
  /**
   * A reference to a custom [selection manager](https://developers.arcgis.com/javascript/latest/references/core/views/SelectionManager/). Otherwise, the selection operation
   * uses the selection manager on the provided view.
   *
   * @since 5.1
   */
  get selectionManager(): SelectionManager | null | undefined;
  /**
   * Indicates whether the selection operation should only update the selection when the operation
   * successfully completes, rather than while actively drawing.
   *
   * @default true
   * @since 5.1
   */
  get selectOnComplete(): boolean;
  /**
   * A reference to sources that should be used to determine selections.
   *
   * @since 5.1
   */
  accessor sources: SelectionSource[] | null | undefined;
  /**
   * Reference to the current drawing tool being used by the selection operation.
   *
   * @default ""
   * @since 5.1
   */
  get toolName(): SelectionToolName;
  /**
   * Reference to the current type of selection operation.
   *
   * @default "add"
   * @since 5.1
   */
  accessor type: SelectionOperationType;
  /**
   * Reference to the view being used by the selection operation.
   *
   * @since 5.1
   */
  get view(): SelectableViewUnion;
  /**
   * Cancels the selection operation. Any existing selection identified by the operation is cleared.
   *
   * @since 5.1
   */
  cancel(): void;
  /**
   * Destroys the selection operation.
   *
   * @since 5.1
   */
  destroy(): void;
}