import type AttributeTableFieldOrder from "./support/FieldOrder.js";
import type { JSONSupport } from "../core/JSONSupport.js";
import type { AttributeTableElementUnion } from "./support/types.js";
import type { AttributeTableRelationshipElementProperties } from "./elements/AttributeTableRelationshipElement.js";
import type { AttributeTableGroupElementProperties } from "./elements/AttributeTableGroupElement.js";
import type { AttributeTableFieldElementProperties } from "./elements/AttributeTableFieldElement.js";
import type { AttributeTableAttachmentElementProperties } from "./elements/AttributeTableAttachmentElement.js";
import type { AttributeTableFieldOrderProperties } from "./support/FieldOrder.js";

export interface AttributeTableTemplateProperties {
  /**
   * An array of [attribute table element](https://developers.arcgis.com/javascript/latest/references/core/tables/elements/AttributeTableElement/)
   * objects that represent an ordered list of table elements.
   *
   * Table elements are designed to allow the table author the ability to
   * define the layout for fields when displaying and/or editing data.
   *
   * > [!WARNING]
   * >
   * > Nested group table elements are not supported.
   *
   * @see [AttributeTableAttachmentElement](https://developers.arcgis.com/javascript/latest/references/core/tables/elements/AttributeTableAttachmentElement/)
   * @see [AttributeTableFieldElement](https://developers.arcgis.com/javascript/latest/references/core/tables/elements/AttributeTableFieldElement/)
   * @see [AttributeTableGroupElement](https://developers.arcgis.com/javascript/latest/references/core/tables/elements/AttributeTableGroupElement/)
   */
  elements?: ((AttributeTableAttachmentElementProperties & { type: "attachment" }) | (AttributeTableFieldElementProperties & { type: "field" }) | (AttributeTableGroupElementProperties & { type: "group" }) | (AttributeTableRelationshipElementProperties & { type: "relationship" }))[] | null;
  /** An Array of [AttributeTableFieldOrder](https://developers.arcgis.com/javascript/latest/references/core/tables/support/FieldOrder/) objects indicating the records' sort order. */
  orderByFields?: AttributeTableFieldOrderProperties[] | null;
}

/**
 * An `AttributeTableTemplate` manages the configuration of how the [FeatureTable](https://developers.arcgis.com/javascript/latest/references/core/widgets/FeatureTable/) widget displays its columns. This template allows you to define properties such as visibility, order, and sorting of the table's columns. It can be applied directly to a [FeatureLayer.attributeTableTemplate](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#attributeTableTemplate), [CSVLayer.attributeTableTemplate](https://developers.arcgis.com/javascript/latest/references/core/layers/CSVLayer/#attributeTableTemplate), [GeoJSONLayer.attributeTableTemplate](https://developers.arcgis.com/javascript/latest/references/core/layers/GeoJSONLayer/#attributeTableTemplate), [CatalogFootprintLayer.attributeTableTemplate](https://developers.arcgis.com/javascript/latest/references/core/layers/catalog/CatalogFootprintLayer/#attributeTableTemplate), [SubtypeSublayer.attributeTableTemplate](https://developers.arcgis.com/javascript/latest/references/core/layers/support/SubtypeSublayer/#attributeTableTemplate), a [FeatureTable.attributeTableTemplate](https://developers.arcgis.com/javascript/latest/references/core/widgets/FeatureTable/#attributeTableTemplate), or [FeatureTable's view model](https://developers.arcgis.com/javascript/latest/references/core/widgets/FeatureTable/FeatureTableViewModel/#attributeTableTemplate). The `AttributeTableTemplate` consists of various [elements](https://developers.arcgis.com/javascript/latest/references/core/tables/AttributeTableTemplate/#elements) that represent specific types of columns in a table. It can be serialized to JSON, enabling the persistence of the table's configuration. This feature facilitates easy sharing and reuse of table configurations across different applications.
 *
 * Tables can be created with a variety of elements, including:
 * * [AttributeTableFieldElement](https://developers.arcgis.com/javascript/latest/references/core/tables/elements/AttributeTableFieldElement/): Represents a column within the table that represents an individual field.
 * * [AttributeTableAttachmentElement](https://developers.arcgis.com/javascript/latest/references/core/tables/elements/AttributeTableAttachmentElement/): Represents a column within the table that represents an attachment.
 * * [AttributeTableRelationshipElement](https://developers.arcgis.com/javascript/latest/references/core/tables/elements/AttributeTableRelationshipElement/): Represents a column within the table that represents a relationship.
 * * [AttributeTableGroupElement](https://developers.arcgis.com/javascript/latest/references/core/tables/elements/AttributeTableGroupElement/): Represents a group of `field`, `relationship`, or `attachment` elements in the table.
 *
 * If a table is configured using another application such as [Map Viewer](https://doc.arcgis.com/en/arcgis-online/manage-data/show-tables-mv.htm), the resulting saved layer or web map [item's](https://doc.arcgis.com/en/arcgis-online/get-started/item-details.htm) JSON will contain a [attributeTableInfo](https://developers.arcgis.com/web-map-specification/objects/attributeTableInfo/) object.
 *
 * > [!WARNING]
 * >
 * > **Considerations**
 * >
 * > The layers that honor the `attributeTableTemplate` property are:
 * > CatalogFootprintLayer
 * > CSVLayer
 * > FeatureLayer
 * > GeoJSONLayer
 * > MapImageLayer (sublayer)
 * > SubtypeSublayer
 * > SceneLayer
 * >
 * > This class differs from [TableTemplate](https://developers.arcgis.com/javascript/latest/references/core/widgets/FeatureTable/support/TableTemplate/). The `TableTemplate` class provides more fine-grained control over how the table is rendered within an application by offering more advanced configurations such as custom cell rendering, column formatting, and more. `TableTemplate` is useful for application-level development that remains within an application. Use `AttributeTableTemplate` to access the table's settings across different applications since they can be saved within a webmap or layer. Please refer to the [TableTemplate](https://developers.arcgis.com/javascript/latest/references/core/widgets/FeatureTable/support/TableTemplate/) documentation for more information.
 * >
 * > The [FeatureTable](https://developers.arcgis.com/javascript/latest/references/core/widgets/FeatureTable/) prioritizes the table's configurations in the following order:
 * >
 * > 1. The [TableTemplate](https://developers.arcgis.com/javascript/latest/references/core/widgets/FeatureTable/support/TableTemplate/) defined in the FeatureTable.
 * > 2. The [FeatureTable.attributeTableTemplate](https://developers.arcgis.com/javascript/latest/references/core/widgets/FeatureTable/#attributeTableTemplate)  defined in the FeatureTable.
 * > 3. The `attributeTableTemplate` defined in the layer or standalone table.
 * > 4. Default columns are generated based on the layer's fields if no table templates exist.
 *
 * @since 4.31
 * @see [FeatureTable](https://developers.arcgis.com/javascript/latest/references/core/widgets/FeatureTable/)
 * @see [AttributeTableElement](https://developers.arcgis.com/javascript/latest/references/core/tables/elements/AttributeTableElement/)
 * @see [Sample - FeatureTable Component](https://developers.arcgis.com/javascript/latest/sample-code/feature-table/)
 * @see [Web Map Specification - attributeTableInfo](https://developers.arcgis.com/web-map-specification/objects/attributeTableInfo/)
 */
export default class AttributeTableTemplate extends JSONSupport {
  constructor(properties?: AttributeTableTemplateProperties);
  /**
   * An array of [attribute table element](https://developers.arcgis.com/javascript/latest/references/core/tables/elements/AttributeTableElement/)
   * objects that represent an ordered list of table elements.
   *
   * Table elements are designed to allow the table author the ability to
   * define the layout for fields when displaying and/or editing data.
   *
   * > [!WARNING]
   * >
   * > Nested group table elements are not supported.
   *
   * @see [AttributeTableAttachmentElement](https://developers.arcgis.com/javascript/latest/references/core/tables/elements/AttributeTableAttachmentElement/)
   * @see [AttributeTableFieldElement](https://developers.arcgis.com/javascript/latest/references/core/tables/elements/AttributeTableFieldElement/)
   * @see [AttributeTableGroupElement](https://developers.arcgis.com/javascript/latest/references/core/tables/elements/AttributeTableGroupElement/)
   */
  get elements(): AttributeTableElementUnion[] | null | undefined;
  set elements(value: ((AttributeTableAttachmentElementProperties & { type: "attachment" }) | (AttributeTableFieldElementProperties & { type: "field" }) | (AttributeTableGroupElementProperties & { type: "group" }) | (AttributeTableRelationshipElementProperties & { type: "relationship" }))[] | null | undefined);
  /** An Array of [AttributeTableFieldOrder](https://developers.arcgis.com/javascript/latest/references/core/tables/support/FieldOrder/) objects indicating the records' sort order. */
  get orderByFields(): AttributeTableFieldOrder[] | null | undefined;
  set orderByFields(value: AttributeTableFieldOrderProperties[] | null | undefined);
  /**
   * Creates a deep clone of the AttributeTableTemplate class.
   *
   * @returns A deep clone of the AttributeTableTemplate instance.
   */
  clone(): AttributeTableTemplate;
}