import type Accessor from "./Accessor.js";

/** Promise mixin. */
export abstract class EsriPromiseMixin {
  constructor(...args: any[]);
  /**
   * `isFulfilled()` may be used to verify if creating an instance of the class is fulfilled (either resolved or rejected).
   * If it is fulfilled, `true` will be returned.
   *
   * @returns Indicates whether creating an instance of the class has been fulfilled (either resolved or rejected).
   */
  isFulfilled(): boolean;
  /**
   * `isRejected()` may be used to verify if creating an instance of the class is rejected.
   * If it is rejected, `true` will be returned.
   *
   * @returns Indicates whether creating an instance of the class has been rejected.
   */
  isRejected(): boolean;
  /**
   * `isResolved()` may be used to verify if creating an instance of the class is resolved.
   * If it is resolved, `true` will be returned.
   *
   * @returns Indicates whether creating an instance of the class has been resolved.
   */
  isResolved(): boolean;
  /**
   * `when()` may be leveraged once an instance of the class is created. This method takes two input parameters: an `onFulfilled` function and an `onRejected` function.
   * The `onFulfilled` executes when the instance of the class loads. The
   * `onRejected` executes if the instance of the class fails to load.
   *
   * @param onFulfilled - The function to call when the promise resolves.
   * @param onRejected - The function to execute when the promise fails.
   * @returns Returns a new promise for the result of `onFulfilled` that may be used to chain additional functions.
   * @since 4.6
   * @example
   * // Although this example uses MapView, any class instance that is a promise may use when() in the same way
   * let view = new MapView();
   * view.when(function(){
   *   // This function will execute once the promise is resolved
   * }, function(error){
   *   // This function will execute if the promise is rejected due to an error
   * });
   */
  when<TResult1 = this, TResult2 = never>(onFulfilled?: OnFulfilledCallback<this, TResult1> | null | undefined, onRejected?: OnRejectedCallback<TResult2> | null | undefined): Promise<TResult1 | TResult2>;
}

export abstract class EsriPromise extends EsriPromiseSuperclass {}
declare const EsriPromiseSuperclass: & typeof Accessor & typeof EsriPromiseMixin

/** @since 5.0 */
export type OnFulfilledCallback<T, TResult> = ((value: T) => TResult | PromiseLike<TResult>) | null | undefined;

/** @since 5.0 */
export type OnRejectedCallback<TResult> = ((reason: any) => TResult | PromiseLike<TResult>) | null | undefined;