import type { JSONSupport, JSONSupportMixinProperties } from "../../core/JSONSupport.js";

export interface AttachmentQueryProperties extends JSONSupportMixinProperties, Partial<Pick<AttachmentQuery, "attachmentsWhere" | "attachmentTypes" | "cacheHint" | "globalIds" | "keywords" | "name" | "num" | "objectIds" | "orderByFields" | "returnMetadata" | "size" | "start" | "where">> {}

/**
 * This class defines parameters for executing queries for feature attachments from a
 * [feature layer](https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html).
 * Once an AttachmentQuery object's properties are defined, it can then be passed into the
 * [executeAttachmentQuery()](https://developers.arcgis.com/javascript/latest/api-reference/esri-rest-query.html#executeAttachmentQuery) or
 * [FeatureLayer#queryAttachments()](https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#queryAttachments) methods,
 * which will return [attachmentInfos](https://developers.arcgis.com/javascript/latest/api-reference/esri-rest-query-support-AttachmentInfo.html)
 * grouped by the source feature objectIds.
 *
 * > [!WARNING]
 * >
 * > **Known Limitations**
 * >
 * > All properties except [objectIds](https://developers.arcgis.com/javascript/latest/api-reference/esri-rest-support-AttachmentQuery.html#objectIds) require an ArcGIS Server service 10.5 or greater, and
 * > feature layer's [capabilities.query.supportsAttachments](https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#capabilities) to be `true`.
 * > When the feature layer's [capabilities.query.supportsAttachments](https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#capabilities)
 * > property is `false`, [objectIds](https://developers.arcgis.com/javascript/latest/api-reference/esri-rest-support-AttachmentQuery.html#objectIds) property only accepts a single `objectId`.
 *
 * @since 4.20
 * @see [query](https://developers.arcgis.com/javascript/latest/api-reference/esri-rest-query.html)
 * @see [capabilities.attachments](https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#capabilities)
 */
export default class AttachmentQuery extends JSONSupport {
  constructor(properties?: AttachmentQueryProperties);
  /**
   * The where clause to be applied to attachment queries. Only attachments that satisfy the `attachmentsWhere`
   * clause will be returned.
   *
   * @example
   * const query = new AttachmentQuery({
   *   where: "1=1", // query all features in the layer
   *   attachmentsWhere: "keywords = 'ladybug, purple'" // attachment queries
   * });
   */
  accessor attachmentsWhere: string | null | undefined;
  /**
   * The file format that is supported by query attachment. For example, `image/jpeg`.
   * See the [ArcGIS REST API documentation](https://developers.arcgis.com/rest/services-reference/query-attachments-feature-service-layer-.htm)
   * for more information on supported attachment types.
   *
   * Requires an ArcGIS Server service 10.5 or greater and
   * feature layer's [capabilities.query.supportsAttachments](https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#capabilities) to be `true`.
   *
   * If the feature layer's [capabilities.attachment.supportsTypeWildcard](https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#capabilities) is `true`, the `attachmentTypes` can include wildcard characters (e.g., `image/*`) to return all attachments of that type.
   *
   * @see [ArcGIS REST API documentation](https://developers.arcgis.com/rest/services-reference/enterprise/query-attachments-feature-service-layer/)
   */
  accessor attachmentTypes: string[] | null | undefined;
  /**
   * Indicates if the service should cache the attachment query results. It only applies if the layer's
   * [capabilities.attachment.supportsCacheHint](https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#capabilities) is set to `true`.
   * Use only for queries that have the same parameters every time the app is used.
   * Some examples of cacheable queries:
   * * Queries based on [preset input](https://developers.arcgis.com/javascript/latest/api-reference/esri-rest-support-AttachmentQuery.html#where), for example, a drop-down list of US states.
   *
   * @since 4.24
   */
  accessor cacheHint: boolean | null | undefined;
  /**
   * An array of globalIds for the features in the layer being queried. The query results will return attachments
   * only for specified global ids.
   *
   * Requires an ArcGIS Server service 10.5 or greater and
   * feature layer's [capabilities.query.supportsAttachments](https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#capabilities)
   * to be `true`.
   */
  accessor globalIds: string[] | null | undefined;
  /**
   * Used to query for attachments that match the provided `keywords`.
   *
   * @see [Query Attachments REST API operation](https://developers.arcgis.com/rest/services-reference/enterprise/query-attachments-feature-service-layer/)
   * @example
   * const query = new AttachmentQuery({
   *   where: "1=1", // query all features in the layer
   *   keywords: ["ladybug", "purple"] // attachment keywords
   * });
   */
  accessor keywords: string[] | null | undefined;
  /**
   * Used to query for attachments that match this `name`.
   *
   * @example
   * const query = new AttachmentQuery({
   *   where: "1=1", // query all features in the layer
   *   attachmentsWhere: "name = 'ladybug.png'" // attachment queries
   * });
   */
  accessor name: string | null | undefined;
  /**
   * The number of features to retrieve. This option should be used in conjunction with the [start property](https://developers.arcgis.com/javascript/latest/api-reference/esri-rest-support-AttachmentQuery.html#start). Use this to
   * implement paging (i.e. to retrieve "pages" of results when querying). Default Value is `10`.
   *
   * If not provided, but an instance of AttachmentQuery has a `start` property, then the default value of `num` is `maxRecordCount`.
   * The maximum value for this parameter is the value of the layer's `maxRecordCount` of the service, which can be found at
   * the REST endpoint of the feature layer.
   *
   * Requires an ArcGIS Server service 10.5 or greater and
   * feature layer's [capabilities.query.supportsAttachments](https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#capabilities) to be `true`.
   */
  accessor num: number | null | undefined;
  /**
   * An array of objectIds of the features to be queried for attachments.
   * When the feature layer's [capabilities.query.supportsAttachments](https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#capabilities) property is
   * `false`, it only accepts a single `objectId`.
   */
  accessor objectIds: number[];
  /**
   * An array of one or more `attachmentInfo` field names on which the returned queried attachments will be sorted. Use `ASC` (ascending) or `DESC` (descending) to control the
   * sort order. The default order is ascending.
   * The `orderByFields` property is only supported when [FeatureLayer.capabilities.attachment.supportsOrderByFields](https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#capabilities) is `true`.
   *
   * @since 4.32
   * @example
   * const query = new AttachmentQuery({
   *   where: "1=1", // query all features in the layer
   *   orderByFields: ["ATT_NAME DESC"] // sort attachments by name in descending order
   * });
   */
  accessor orderByFields: string[] | null | undefined;
  /**
   * If `true`, the [Exchangeable image file format](https://en.wikipedia.org/wiki/Exif) for the attachment will be included in
   * [AttachmentInfo#exifInfo](https://developers.arcgis.com/javascript/latest/api-reference/esri-rest-query-support-AttachmentInfo.html#exifInfo). The layer's
   * [capabilities.attachment.supportsExifInfo](https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#capabilities) must be `true` for the
   * attachment query to return `exifInfo` for the attachments.
   *
   * @default false
   */
  accessor returnMetadata: boolean;
  /**
   * The file size of the attachment is specified in bytes. You can enter a
   * file size range [1000,15000] to query for attachments. The query result will return
   * all attachments within the specified file size range (1000 - 15000).
   *
   * Requires an ArcGIS Server service 10.5 or greater and
   * feature layer's [capabilities.query.supportsAttachments](https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#capabilities)
   * to be `true`.
   */
  accessor size: [
      number,
      number
  ] | null | undefined;
  /**
   * This option fetches query results by skipping a specified number of records. The query results start from the next record.
   * The default value is `0`. This parameter only applies when the feature layer's
   * [capabilities.query.supportsPagination](https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#capabilities) is `true`. You can use this option to
   * fetch records that are beyond `maxRecordCount`.
   *
   * Requires an ArcGIS Server service 10.5 or greater and
   * feature layer's [capabilities.query.supportsAttachments](https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#capabilities) to be `true`.
   */
  accessor start: number | null | undefined;
  /**
   * The `where` clause to be applied to the layer. Only features that satisfy the `where` clause
   * and are in the list of [objectIds](https://developers.arcgis.com/javascript/latest/api-reference/esri-rest-support-AttachmentQuery.html#objectIds) will be returned. Requires an ArcGIS Server service 10.5 or greater and
   * feature layer's [capabilities.query.supportsAttachments](https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#capabilities)
   * to be `true`.
   */
  accessor where: string | null | undefined;
  /**
   * Creates a deep clone of AttachmentQuery object.
   *
   * @returns A new instance of a AttachmentQuery object equal to the object used to call `.clone()`.
   */
  clone(): AttachmentQuery;
}