import type EsriError from "../core/Error.js";
import type PortalItem from "./PortalItem.js";
import type PortalItemResource from "./PortalItemResource.js";
import type PortalFolder from "./PortalFolder.js";
import type { AbortOptions } from "../core/promiseUtils.js";

export type PortalAuthMode = "anonymous" | "auto" | "immediate" | "no-prompt";

export interface ItemUpdateParameters {
  /**
   * **Optional**. The component used to stream
   * the data represented by the item to the client.
   */
  data?: any;
}

export interface PortalItemResourceAddOrUpdateOptions extends AbortOptions {
  /**
   * Indicates the level of access to the resource. The default is
   *   "inherit" which causes the resource to have the same access level as the owning item.
   *
   * @default "inherit"
   */
  access?: "inherit" | "private";
}

export interface PortalItemResourceWithPath extends PortalItemResource {}

export interface AddItemParameters {
  /**
   * The component used to stream
   * the data represented by the item to the client.
   */
  data?: string | any;
  /**
   * The portal folder in
   * which to store the item.
   */
  folder?: string | PortalFolder;
  /** The item to add to the user's content. */
  item: PortalItem;
}

/** The result of the [PortalUser#deleteItems()](https://developers.arcgis.com/javascript/latest/api-reference/esri-portal-PortalUser.html#deleteItems) method containing the [item](https://developers.arcgis.com/javascript/latest/api-reference/esri-portal-PortalItem.html), if deletion is successful, and error, if any. */
export interface DeleteItemsResult {
  /** The error if the item was not deleted. */
  error?: EsriError | null;
  /** An item from the `items` parameter of [PortalUser#deleteItems()](https://developers.arcgis.com/javascript/latest/api-reference/esri-portal-PortalUser.html#deleteItems). */
  item: PortalItem;
  /** Indicates whether the item was successfully deleted. */
  success: boolean;
}

export interface FetchItemsParameters {
  /** The folder to retrieve items from. When `folder` is not specified, the `includeSubfolderItems` parameter can be used to include items from subfolders. */
  folder?: PortalFolder;
  /**
   * Option to include items from subfolders along with items in the root folder. This parameter does not apply when the `folder` parameter is specified.
   *
   * @default false
   */
  includeSubfolderItems?: boolean;
  /**
   * Option to retrieve items from the recycle bin instead.
   *
   * @default false
   */
  inRecycleBin?: boolean;
  /**
   * The maximum number of results to be included in the result set response. The maximum value allowed
   * is 100. The start property combined with the num property can be used to paginate the search results.
   *
   * @default 10
   */
  num?: number;
  /**
   * A comma-delimited list of fields to sort by. Allowed values are `created`, `modified`, `size`, and `type`.
   *
   * @default created
   */
  sortField?: string;
  /**
   * The order in which to sort the results. Allowed values are `asc` for ascending order and `desc` for descending order.
   *
   * @default asc
   */
  sortOrder?: "asc" | "desc";
  /**
   * The index of the first entry in the result set response. The index is 1-based.
   *
   * @default 1
   */
  start?: number;
}

/** The result of the [PortalUser#fetchItems()](https://developers.arcgis.com/javascript/latest/api-reference/esri-portal-PortalUser.html#fetchItems) method containing an array of the fetched [portal items](https://developers.arcgis.com/javascript/latest/api-reference/esri-portal-PortalItem.html), the next entry index, and the total number of results. */
export interface FetchItemsResult {
  /** An array containing user's portal items. */
  items: PortalItem[];
  /** The next entry index if the current result set doesn't contain all results. */
  nextStart: number;
  /** The total number of results. */
  total: number;
}

export interface FetchRelatedItemsParameters {
  /**
   * The direction of the relationship. Can either
   *   be `forward` (from origin to destination) or `reverse` (from destination to origin).
   */
  direction?: "forward" | "reverse";
  /**
   * The type of relationship between the two items.
   * See [Relationship types](https://developers.arcgis.com/rest/users-groups-and-items/relationship-types.htm) for a complete listing of types.
   */
  relationshipType: string;
}

export type PortalGroupSortField = "title" | "uploaded" | "modified" | "username" | "created" | "type" | "owner" | "avg-rating" | "num-ratings" | "num-comments" | "num-views";

/** Members returned in the result of [PortalGroup#fetchMembers()](https://developers.arcgis.com/javascript/latest/api-reference/esri-portal-PortalGroup.html#fetchMembers). */
export interface Members {
  /** The admins. */
  admins: string[];
  /** The owner. */
  owner: string;
  /** The users. */
  users: string[];
}

export interface FetchBasemapsOptions extends AbortOptions {
  /**
   * When `true` the basemaps based on [Portal#basemapGalleryGroupQuery3D](https://developers.arcgis.com/javascript/latest/api-reference/esri-portal-Portal.html#basemapGalleryGroupQuery3D) are also fetched,
   *  if no `basemapGalleryGroupQuery` is passed as an argument. When `true` and a custom `basemapGalleryGroupQuery` is passed, also 3D basemaps from the custom group are fetched.
   *  When not specified, it will default to [Portal#use3dBasemaps](https://developers.arcgis.com/javascript/latest/api-reference/esri-portal-Portal.html#use3dBasemaps).
   */
  include3d?: boolean;
}