import type ValidateNetworkTopologyResult from "../../rest/networks/support/ValidateNetworkTopologyResult.js";
import type { RequestOptions } from "../../request/types.js";
import type { ValidateNetworkTopologyResultProperties } from "../../rest/networks/support/ValidateNetworkTopologyResult.js";

export interface TopologyValidationJobInfoProperties extends ValidateNetworkTopologyResultProperties, Partial<Pick<TopologyValidationJobInfo, "status" | "statusUrl">> {
  /** The last date and time the service was updated. */
  lastUpdatedTime?: (Date | number | string) | null;
  /** The date and time in which [Network.submitTopologyValidationJob()](https://developers.arcgis.com/javascript/latest/references/core/networks/Network/#submitTopologyValidationJob) is first called. */
  submissionTime?: (Date | number | string) | null;
}

export type TopologyValidationJobStatus = "job-waiting" | "job-executing" | "job-succeeded";

export interface WaitForValidateOptions {
  /**
   * The time in millisecond between remote job status requests.
   *
   * @default 1000
   */
  interval?: number;
  /**
   * Callback function that is called at the specified interval.
   *                                            Use this method to monitor job status and messages.
   */
  statusCallback?: (result: TopologyValidationJobInfo) => void;
}

/**
 * Represents information pertaining to the execution of an asynchronous [Network.submitTopologyValidationJob()](https://developers.arcgis.com/javascript/latest/references/core/networks/Network/#submitTopologyValidationJob) request on the server.
 *
 * @since 4.26
 * @see [ValidateNetworkTopologyParameters](https://developers.arcgis.com/javascript/latest/references/core/rest/networks/support/ValidateNetworkTopologyParameters/)
 * @see [UtilityNetwork](https://developers.arcgis.com/javascript/latest/references/core/networks/UtilityNetwork/)
 */
export default class TopologyValidationJobInfo extends ValidateNetworkTopologyResult {
  constructor(properties?: TopologyValidationJobInfoProperties);
  /** The last date and time the service was updated. */
  get lastUpdatedTime(): Date | null | undefined;
  set lastUpdatedTime(value: (Date | number | string) | null | undefined);
  /** The job status. */
  status: TopologyValidationJobStatus;
  /** ArcGIS Server Rest API endpoint to the resource that receives the validate network topology request. */
  accessor statusUrl: string;
  /** The date and time in which [Network.submitTopologyValidationJob()](https://developers.arcgis.com/javascript/latest/references/core/networks/Network/#submitTopologyValidationJob) is first called. */
  get submissionTime(): Date | null | undefined;
  set submissionTime(value: (Date | number | string) | null | undefined);
  /**
   * Sends a request for the current state of this job.
   *
   * @param requestOptions - Additional [options](https://developers.arcgis.com/javascript/latest/references/core/request/#request) to be used for the data request
   * (will override requestOptions defined during construction).
   * @returns When resolved, returns a [TopologyValidationJobInfo](https://developers.arcgis.com/javascript/latest/references/core/networks/support/TopologyValidationJobInfo/).
   * @example
   * const extent = new Extent({
   *   xmin: 470789.0888,
   *   ymin: 3597733.2051,
   *   xmax: 531454.2759999996,
   *   ymax: 3639864.802100001,
   *   spatialReference: { wkid: 26911, latestWkid: 26911 }
   * });
   *
   * const result = await network.submitTopologyValidationJob(
   *   new ValidateNetworkTopologyParameters({
   *     validateArea: extent,
   *     gdbVersion: "version.test"
   *   })
   * );
   *
   * const jobInfo = await result.checkJobStatus();
   * console.log("jobInfo.status", jobInfo.status);
   */
  checkJobStatus(requestOptions?: RequestOptions | null): Promise<TopologyValidationJobInfo>;
  /**
   * Stop monitoring this job for status updates.
   *
   * ```
   * // Stop monitoring this job for status updates.
   * jobInfo.destroy();
   * ```
   *
   * @see [waitForJobCompletion()](https://developers.arcgis.com/javascript/latest/references/core/networks/support/TopologyValidationJobInfo/#waitForJobCompletion)
   */
  destroy(): void;
  /**
   * Resolves when an asynchronous job has completed. Optionally job progress can be monitored.
   *
   * @param options - Options. See properties below for object specifications.
   * @returns When resolved, returns a [TopologyValidationJobInfo](https://developers.arcgis.com/javascript/latest/references/core/networks/support/TopologyValidationJobInfo/).
   * @example
   * // Submit an asynchronous validate network topology job. Display the remote job status every 1.5 seconds.
   * const extent = new Extent({
   *   xmin: 470789.0888,
   *   ymin: 3597733.2051,
   *   xmax: 531454.2759999996,
   *   ymax: 3639864.802100001,
   *   spatialReference: { wkid: 26911, latestWkid: 26911 }
   * });
   *
   * const result = await network.submitTopologyValidationJob(
   *   new ValidateNetworkTopologyParameters({
   *     validateArea: extent,
   *     gdbVersion: "version.test"
   *   })
   * );
   *
   * const options = {
   *   interval: 1500,
   *   statusCallback: (j) => {
   *     console.log("Job Status: ", j.jobStatus);
   *   }
   * };
   *
   * await jobInfo.waitForJobCompletion(options);
   */
  waitForJobCompletion(options?: WaitForValidateOptions): Promise<TopologyValidationJobInfo>;
}