import type EsriError from "./Error.js";
import type { EsriPromise } from "./Promise.js";
import type { AbortOptions } from "./promiseUtils.js";

export interface LoadableMixinProperties {}

/**
 * Loadable is a mixin class that provides a standardized way to load resources
 * asynchronously. Many classes in the API that load resources from a remote
 * source extend this class.
 *
 * @since 4.0
 */
export abstract class LoadableMixin {
  constructor(...args: any[]);
  /** The Error object returned if an error occurred while loading. */
  get loadError(): EsriError | null | undefined;
  /**
   * Represents the status of a [load()](https://developers.arcgis.com/javascript/latest/api-reference/esri-core-Loadable.html#load) operation.
   *
   * Value | Description
   * ------|------------
   * not-loaded | The object's resources have not loaded.
   * loading | The object's resources are currently loading.
   * loaded | The object's resources have loaded without errors.
   * failed | The object's resources failed to load. See [loadError](https://developers.arcgis.com/javascript/latest/api-reference/esri-core-Loadable.html#loadError) for more details.
   *
   * @default "not-loaded"
   */
  get loadStatus(): "not-loaded" | "loading" | "failed" | "loaded";
  /** A list of warnings which occurred while loading. */
  get loadWarnings(): any[];
  /** Cancels a [load()](https://developers.arcgis.com/javascript/latest/api-reference/esri-core-Loadable.html#load) operation if it is already in progress. */
  cancelLoad(): this;
  /**
   * Loads the resources referenced by this class. This method automatically
   * executes for a [View](https://developers.arcgis.com/javascript/latest/api-reference/esri-views-View.html) and all of the resources
   * it references in [Map](https://developers.arcgis.com/javascript/latest/api-reference/esri-Map.html) if the view is constructed with
   * a map instance.
   *
   * This method must be called by the developer when accessing a resource that will not be
   * loaded in a [View](https://developers.arcgis.com/javascript/latest/api-reference/esri-views-View.html).
   *
   * The `load()` method only triggers the loading of the resource the first time it is called. The subsequent calls return the same promise.
   *
   * It's possible to provide a `signal` to stop being interested into a `Loadable` instance load status.
   * When the signal is aborted, the instance does not stop its loading process, only [cancelLoad()](https://developers.arcgis.com/javascript/latest/api-reference/esri-core-Loadable.html#cancelLoad) can abort it.
   *
   * @param options - Additional options.
   * @returns Resolves when the resources have [loaded](https://developers.arcgis.com/javascript/latest/api-reference/esri-core-Loadable.html#loadStatus).
   */
  load(options?: AbortOptions | null | undefined): Promise<this>;
}

export abstract class Loadable extends LoadableSuperclass {}
declare const LoadableSuperclass: & typeof EsriPromise & typeof LoadableMixin