import type { ContentItem } from './content.ts';
import type { Facet } from './facets.ts';
import type { ProductGroup } from './products.ts';
import type { Sort } from './sort.ts';


export type Visualization = 'CAROUSEL' | 'GRID';

export type Algorithm =
  'TOP_PRODUCTS' |
  'PERSONAL' |
  'CART' |
  'STYLE_WITH' |
  'ALTERNATIVES' |
  'UPSELL' |
  'NEWEST_PRODUCTS' |
  'FAVORITES' |
  'MORE_FROM_SERIES' |
  'RECENTLY_VIEWED' |
  'ADD_TO_CART_RECS';

export interface RecommendationList {
  /**
   * The identifier for this list. Typically a short name describing
   * where on the page it's used.
   */
  id: string;
  /**
   * The algorithm type being used for this recommendationList. It's possible to change
   * algorithm for pages in the Elevate app, so this value could be different from the algorithm
   * used in the POST request.
   */
  algorithm: Algorithm;
  /** ProductGroups that matched the algorithm, limit of the input or saved setting */
  productGroups: ProductGroup[];
  /**
   * Indicates whether this recommendation list has been hidden or not in the Elevate app.
   * Hidden product lists are still returned, but their `productGroups` list is empty.
   */
  visible: boolean;
  /** The presentation text for list. Can be `undefined` if the list item label is left empty in the app. */
  label?: string;
  /** A URL to use to link to a full product listing for the recommendation selection */
  showMoreLink?: string;
  /** Indicator on how the list should be presented. */
  visualization: Visualization;
}

export interface SponsoredList extends RecommendationList {
  /** Ticket used to track impressions of a list, i.e. if a list has been shown to a user.*/
  impressionTicket?: string;
  /** The winning brands in the bid for the sponsored list*/
  winners: string[];
}

export interface RecommendationListPage {
  /** Collection of recommendation lists, defined either by POST body or PageSetting in apps */
  recommendationLists: RecommendationList[];
}

export interface ContentList {
  /** List identifier */
  id: string;
  /** The total number of content items that matches filter and query (if applicable) */
  totalHits: number;
  /** List of matched content items */
  items: ContentItem[];
}

export interface ContentListPage {
  /**
   * A list of lists of requested content, as specified in request body. Will be
   * empty unless specified in request body.
   */
  contentLists: ContentList[];
}

export interface PrimaryList {
  /** How the ProductGrups are sorted */
  sort: Sort;
  /** Collection of ProductGroup */
  productGroups: ProductGroup[];
  /** Total number of ProductGroup hits */
  totalHits: number;
  /** Collection of Facet */
  facets: Facet[];
}

export type SecondaryList = Pick<PrimaryList, 'productGroups' | 'totalHits'>;
