import type DynamicDataLayer from "./DynamicDataLayer.js";
import type DynamicMapLayer from "./DynamicMapLayer.js";
import type { JSONSupport } from "../../core/JSONSupport.js";

/** @since 5.0 */
export interface JoinTableDataSourceProperties extends Partial<Pick<JoinTableDataSource, "joinType" | "leftTableKey" | "leftTableSource" | "rightTableKey" | "rightTableSource">> {}

/** @since 5.0 */
export type JoinType = "left-inner-join" | "left-outer-join";

/**
 * The result of an on-the-fly join operation at runtime. Nested joins are supported.
 * To use nested joins, set either `leftTableSource` or `rightTableSource` to `join-table`.
 *
 * @since 5.0
 * @see [Sample - MapImageLayer: dynamic data layer with table join](https://developers.arcgis.com/javascript/latest/sample-code/layers-dynamicdatalayer-table-join/)
 * @see [ArcGIS REST API - Join table data source](https://developers.arcgis.com/rest/services-reference/enterprise/data-source-object/#join-table-data-source)
 * @example
 * let layer = new MapImageLayer({
 *   url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer",
 *   sublayers: [{
 *     id: 0,
 *     renderer: renderer,
 *     opacity: 0.9,
 *     source: {
 *       type: "data-layer",
 *       dataSource: {
 *         type: "join-table",
 *         leftTableSource: {
 *           type: "map-layer",
 *           mapLayerId: 3
 *         },
 *         rightTableSource: {
 *           type: "data-layer",
 *           dataSource: {
 *             type: "table",
 *             workspaceId: "CensusFileGDBWorkspaceID",
 *             dataSourceName: "ancestry"
 *           }
 *         },
 *         leftTableKey: "STATE_NAME",
 *         rightTableKey: "State",
 *         joinType: "left-outer-join"
 *       }
 *     }
 *   }]
 * });
 */
export default class JoinTableDataSource extends JSONSupport {
  constructor(properties?: JoinTableDataSourceProperties);
  /**
   * The type of join that will be performed.
   *
   * Possible Value | Description
   * ---------------|------------
   * left-outer-join | Unmatched records in the left table source are preserved and joined with `null` values in the right table source.
   * left-inner-join | Records in the left table source are discarded if they are unmatched with records in the right table source.
   *
   * @since 5.0
   */
  joinType: JoinType;
  /**
   * The field name used for joining or matching records in the left table to
   * records in the right table.
   *
   * @since 5.0
   */
  accessor leftTableKey: string;
  /**
   * The left table for joining to the right table source. This can either be a dynamic map layer or a dynamic data layer. The dynamic data layer may contain another join data source used for nested joining.
   *
   * @since 5.0
   */
  accessor leftTableSource: DynamicMapLayer | DynamicDataLayer;
  /**
   * The field name used for joining or matching records in the right table
   * to records in the left table.
   *
   * @since 5.0
   */
  accessor rightTableKey: string;
  /**
   * The right table for joining to the left table source. This can either be a dynamic map layer or a dynamic data layer. The dynamic data layer may contain another join data source used for nested joining.
   *
   * @since 5.0
   */
  accessor rightTableSource: DynamicMapLayer | DynamicDataLayer;
  /**
   * This value is always `join-table` and is inferred when other
   * join table properties of this object are set.
   *
   * @since 5.0
   */
  get type(): "join-table";
}