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

export interface TraceJobInfoProperties extends TraceResultProperties, Partial<Pick<TraceJobInfo, "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 TraceJobStatus = "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: TraceJobInfo) => void;
}

/**
 * Represents information pertaining to the execution of an asynchronous request on the server.
 *
 * @since 4.27
 * @see [TraceParameters](https://developers.arcgis.com/javascript/latest/references/core/rest/networks/support/TraceParameters/)
 * @see [UtilityNetwork](https://developers.arcgis.com/javascript/latest/references/core/networks/UtilityNetwork/)
 */
export default class TraceJobInfo extends TraceResult {
  constructor(properties?: TraceJobInfoProperties);
  /** 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: TraceJobStatus;
  /** 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 [TraceJobInfo](https://developers.arcgis.com/javascript/latest/references/core/networks/support/TraceJobInfo/).
   * @example
   * const traceLocation = TraceLocation.fromJSON({
   *   traceLocationType: "startingPoint",
   *   globalId: "{BBF88249-6BAD-438F-9DBB-0E48DD89EECA}",
   *   percentAlong: 0.5805425412252266
   * });
   *
   * const traceParameters = TraceParameters.fromJSON({
   *   traceConfigurationGlobalId: "{DF22DA8D-6EC0-408B-A8B2-E468EC7DC9BF}",
   *   resultTypes: [
   *     {
   *       type: "elements",
   *       includeGeometry: false,
   *       includePropagatedValues: false,
   *       networkAttributeNames: [],
   *       diagramTemplateName: "",
   *       resultTypeFields: []
   *     },
   *     {
   *       type: "aggregatedGeometry",
   *       includeGeometry: false,
   *       includePropagatedValues: false,
   *       networkAttributeNames: [],
   *       diagramTemplateName: "",
   *       resultTypeFields: []
   *     }
   *   ],
   *   traceType: "subnetwork"
   * });
   * traceParameters.traceLocations = [traceLocation];
   *
   * const jobInfo = await network.submitTraceJob(traceParameters);
   * await jobInfo.checkJobStatus();
   */
  checkJobStatus(requestOptions?: RequestOptions | null): Promise<TraceJobInfo>;
  /**
   * Stop monitoring this job for status updates.
   *
   * ```
   * // Stop monitoring this job for status updates.
   * jobInfo.destroy();
   * ```
   *
   * @see [TopologyValidationJobInfo.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 [TraceJobInfo](https://developers.arcgis.com/javascript/latest/references/core/networks/support/TraceJobInfo/).
   * @example
   * // Submit an asynchronous trace job.
   * const traceLocation: TraceLocation = TraceLocation.fromJSON({
   *   traceLocationType: "startingPoint",
   *   globalId: "{BBF88249-6BAD-438F-9DBB-0E48DD89EECA}",
   *   percentAlong: 0.5805425412252266
   * });
   *
   * const traceParameters: TraceParameters = TraceParameters.fromJSON({
   * traceConfigurationGlobalId: "{DF22DA8D-6EC0-408B-A8B2-E468EC7DC9BF}",
   *   moment: 1554214441244,
   *   gdbVersion: "SDE.DEFAULT",
   *   resultTypes: [
   *     {
   *       type: "elements",
   *       includeGeometry: false,
   *       includePropagatedValues: false,
   *       networkAttributeNames: [],
   *       diagramTemplateName: "",
   *       resultTypeFields: []
   *     },
   *     {
   *       type: "aggregatedGeometry",
   *       includeGeometry: false,
   *       includePropagatedValues: false,
   *       networkAttributeNames: [],
   *       diagramTemplateName: "",
   *       resultTypeFields: []
   *     }
   *   ],
   *   traceType: "subnetwork"
   * });
   * traceParameters.traceLocations = [traceLocation];
   *
   * const jobInfo = await network.submitTraceJob(traceParameters);
   *
   * await jobInfo.waitForJobCompletion();
   */
  waitForJobCompletion(options?: WaitForValidateOptions): Promise<TraceJobInfo>;
}