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";

/** @since 5.0 */
export type State = "disabled" | "ready" | "error" | "loading";

/** @since 5.0 */
export interface FeatureFormattedAttributes {
  /**
   * 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.
   *
   * @since 5.0
   */
  global: Record<string, any>;
  /**
   * 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).
   *
   * @since 5.0
   */
  content: Record<string, any>[];
}

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

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

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

/**
 * 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.
 *
 * @since 5.0
 */
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
   * @since 5.0
   */
  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
   * @since 5.0
   */
  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
   * @since 5.0
   */
  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
   * @since 5.0
   */
  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
   * @since 5.0
   */
  mediaContent?: 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
   * @since 5.0
   */
  textContent?: 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
   * @since 5.0
   */
  relationshipContent?: 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
   * @since 5.0
   */
  utilityNetworkAssociationsContent?: boolean;
}