import type Accessor from "../../core/Accessor.js";
import type EsriError from "../../core/Error.js";
import type IPortalItem from "../../portal/PortalItem.js";
import type { PortalItemProperties } from "../../portal/PortalItem.js";

/** @since 5.0 */
export interface FileLinkProperties extends Partial<Pick<FileLink, "count" | "error" | "extension" | "formattedName" | "name" | "state" | "url">> {
  /**
   * The [PortalItem](https://developers.arcgis.com/javascript/latest/references/core/portal/PortalItem/) of the template.
   *
   * @since 5.0
   */
  portalItem?: PortalItemProperties | null;
}

/**
 * Represents an exported map request from the result of the Print widget.
 * Successful exports will have a URL that links to the printout. Failed ones will have information on what went wrong.
 *
 * @since 5.0
 * @example
 * const [Print, esriConfig] = await $arcgis.import([
 *   "@arcgis/core/widgets/Print.js",
 *   "@arcgis/core/config.js"
 * ]);
 * // ...
 *
 * view.when(function () {
 *   print = new Print({
 *     view: view,
 *     // specify your own print service
 *     printServiceUrl:
 *       "https://utility.arcgisonline.com/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task"
 *   });
 *
 *   // Add widget to the top right corner of the view
 *   view.ui.add(print, "top-right");
 *
 *   // use a requestInterceptor to monitor the print widget
 *   // for print completion
 *   esriConfig.request.interceptors.push({
 *     // set the `urls` property to the URL of the print service so that this
 *     // interceptor only applies to requests made to the print service URL
 *     urls: print.printServiceUrl,
 *     // use the AfterInterceptorCallback to interrogate the exportedLinks property
 *     after: function(response) {
 *       console.log("exportedLinks: ", print.exportedLinks.items[0]);
 *     }
 *   });
 * });
 */
export default class FileLink extends Accessor {
  constructor(properties?: FileLinkProperties);
  /**
   * The location of the FileLink element in the array.
   *
   * @since 5.0
   */
  accessor count: number | null | undefined;
  /**
   * The [Error](https://developers.arcgis.com/javascript/latest/references/core/core/Error/) from the Print widget, if any.
   *
   * @since 5.0
   */
  accessor error: EsriError | null | undefined;
  /**
   * The [file type](https://developers.arcgis.com/javascript/latest/references/core/widgets/Print/TemplateOptions/#format) of the print-out.
   *
   * @since 5.0
   */
  accessor extension: string | null | undefined;
  /**
   * The name of the FileLink, formatted with name, extension and count.
   *
   * @since 5.0
   */
  accessor formattedName: string | null | undefined;
  /**
   * The [TemplateOptions.fileName](https://developers.arcgis.com/javascript/latest/references/core/widgets/Print/TemplateOptions/#fileName)
   * or [TemplateOptions.title](https://developers.arcgis.com/javascript/latest/references/core/widgets/Print/TemplateOptions/#title) of the print-out.
   *
   * @since 5.0
   */
  accessor name: string | null | undefined;
  /**
   * The [PortalItem](https://developers.arcgis.com/javascript/latest/references/core/portal/PortalItem/) of the template.
   *
   * @since 5.0
   */
  get portalItem(): IPortalItem | null | undefined;
  set portalItem(value: PortalItemProperties | null | undefined);
  /**
   * The state of the print-out. Either `"ready"` or `"pending"` or `"error"`.
   *
   * @default "pending"
   * @since 5.0
   */
  accessor state: "ready" | "error" | "pending";
  /**
   * The [Print.printServiceUrl](https://developers.arcgis.com/javascript/latest/references/core/widgets/Print/#printServiceUrl) of the print-out.
   *
   * @default ""
   * @since 5.0
   */
  accessor url: string;
}