import type Graphic from "../../Graphic.js";
import type SpatialReference from "../../geometry/SpatialReference.js";
import type Field from "../../layers/support/Field.js";
import type Relationship from "../../layers/support/Relationship.js";
import type StatisticDefinition from "../../rest/support/StatisticDefinition.js";

export type State = "disabled" | "ready" | "error" | "loading";

export interface FeatureFormattedAttributes {
  /**
   * The formatted attributes for an individual content element. This is derived from the
   * [PopupTemplate](https://developers.arcgis.com/javascript/latest/api-reference/esri-PopupTemplate.html), or
   * per an individual content element. This element is defined with a [FieldsContent](https://developers.arcgis.com/javascript/latest/api-reference/esri-popup-content-FieldsContent.html)
   * popup element set on the PopupTemplate's [PopupTemplate#content](https://developers.arcgis.com/javascript/latest/api-reference/esri-PopupTemplate.html#content).
   */
  content: Record<string, any>[];
  /**
   * The formatted attributes specified at the root level of the [PopupTemplate](https://developers.arcgis.com/javascript/latest/api-reference/esri-PopupTemplate.html)
   * using the [PopupTemplate#fieldInfos](https://developers.arcgis.com/javascript/latest/api-reference/esri-PopupTemplate.html#fieldInfos) property.
   */
  global: Record<string, any>;
}

export interface LastEditInfo {
  /** Date that the edit was performed. */
  date: string;
  /** The type of edit that was performed on the feature. */
  type: "edit" | "create";
  /** User who performed the last edit on a feature. */
  user: string;
}

/** Information about the layer associated with the feature. */
export interface LayerInfo {
  /** An array of the layer's fields. */
  fields: Field[];
  /** The object ID field of the layer. */
  objectIdField: string;
  /** An array of the layer's relationships. */
  relationships: Relationship[];
  /** Indicates whether the layer supports statistics. */
  supportsStatistics: boolean;
}

/** Information about the features that are related to the current feature. */
export interface RelatedInfo {
  /** The layer information for the related features. */
  layerInfo?: LayerInfo;
  /** An array of statistics to be calculated for the related features. */
  outStatistics?: StatisticDefinition[];
  /** An array of features related to the current feature. */
  relatedFeatures?: Graphic[];
  /** An array of related fields that are related to the current feature. */
  relatedFields?: string[];
  /** An array of related features with statistics for the current feature. */
  relatedStatsFeatures?: Graphic[];
  /** The relationship between the current feature and the related features. */
  relation?: Relationship;
  /** The spatial reference of the source feature. */
  sourceSpatialReference?: SpatialReference;
  /** The URL of the related layer. */
  url: string;
}

/** This object defines specific abilities for the [Feature](https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Feature.html) and [Popup](https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Popup.html) widgets. */
export interface Abilities {
  /**
   * Indicate whether the widget should query and display [attachments](https://developers.arcgis.com/javascript/latest/api-reference/esri-popup-content-AttachmentsContent.html) associated with the feature.
   *
   * @default true
   */
  attachmentsContent?: boolean;
  /**
   * Indicate whether the widget should display animations for charts residing in [media content elements](https://developers.arcgis.com/javascript/latest/api-reference/esri-popup-content-MediaContent.html).
   *
   * @default true
   */
  chartAnimation?: boolean;
  /**
   * Indicate whether the widget should display any [custom content elements](https://developers.arcgis.com/javascript/latest/api-reference/esri-popup-content-CustomContent.html).
   *
   * @default true
   */
  customContent?: boolean;
  /**
   * Indicate whether the widget should display any [fields content elements](https://developers.arcgis.com/javascript/latest/api-reference/esri-popup-content-FieldsContent.html).
   *
   * @default true
   */
  fieldsContent?: boolean;
  /**
   * Indicate whether the widget should display any [media content elements](https://developers.arcgis.com/javascript/latest/api-reference/esri-popup-content-MediaContent.html).
   *
   * @default true
   */
  mediaContent?: boolean;
  /**
   * Indicate whether the widget should display [relationship content elements](https://developers.arcgis.com/javascript/latest/api-reference/esri-popup-content-RelationshipContent.html).
   *
   * @default true
   */
  relationshipContent?: boolean;
  /**
   * Indicate whether the widget should display any [text content elements](https://developers.arcgis.com/javascript/latest/api-reference/esri-popup-content-TextContent.html).
   *
   * @default true
   */
  textContent?: boolean;
  /**
   * Indicate whether the widget should display [utility network associations content elements](https://developers.arcgis.com/javascript/latest/api-reference/esri-popup-content-UtilityNetworkAssociationsContent.html).
   *
   * @default true
   */
  utilityNetworkAssociationsContent?: boolean;
}