import { BlazeWidgetLabel } from '../classes/blaze-widget-label';
import { BlazeRecommendationsType } from '../classes/blaze-recommendations-type'
import {
  BlazeBasePlayerDelegate,
} from '../classes/base-player-delegate';

export interface StoryPageType {
  storyId: string;
  pageId?: string;
}

// Widget events now use the same approach as entry point events
// The BlazeBasePlayerDelegateHandler will handle parsing and validation
export type OnDataLoadStartedEvent = Readonly<any>;
export type OnDataLoadCompleteEvent = Readonly<any>;
export type OnPlayerDidAppearEvent = Readonly<any>;
export type OnPlayerDidDismissEvent = Readonly<any>;
export type OnTriggerCTAEvent = Readonly<any>;
export type OnTriggerPlayerBodyTextLinkEvent = Readonly<any>;
export type OnPlayerEventTriggeredEvent = Readonly<any>;
export type OnPlayerEventTriggeredEventInternal = Readonly<any>;

export type OnTriggerCustomActionButtonEvent = Readonly<any>;

// Widget-specific events that don't have entry point equivalents
export type OnItemClickedEvent = Readonly<any>;

export type OnHeightChangedEventInternal = Readonly<{
  newHeight: number
}>;

export type BlazeDataSourceType =
  {
    labels: BlazeWidgetLabel;
    orderType?: BlazeOrderType;
    labelsPriority?: BlazeWidgetLabel[];
    maxItems?: number;
    advancedOrderType?: BlazeAdvancedOrderType;
    personalizedType?: BlazeDataSourcePersonalizedType;
  }
  |
  {
    ids: string[],
    orderType?: BlazeOrderType,
    advancedOrderType?: BlazeAdvancedOrderType;
  }
  |
  {
    recommendationsType: BlazeRecommendationsType
  }
  |
  {
    type: 'search';
    searchText: string;
    maxItems?: number;
    labels?: BlazeWidgetLabel;
  };

type BlazeOrderType = 'manual' // Manual order. Items are arranged manually according to a custom-defined order.
  | 'recentlyUpdatedFirst' // Recently updated items appear first. Items are ordered based on their most recent update timestamp, with the most recently updated items appearing at the beginning.
  | 'recentlyUpdatedLast' // Recently updated items appear last. Items are ordered based on their most recent update timestamp, with the most recently updated items appearing at the end.
  | 'aToZ' // Items are arranged in alphabetical order from A to Z based on their titles.
  | 'zToA' // Items are arranged in alphabetical order from Z to A based on their titles.
  | 'recentlyCreatedFirst' // Recently created items appear first. Sorts the items by their last creation time in descending order, meaning the most recently created items will be displayed first.
  | 'recentlyCreatedLast' // Recently created items appear last. Sorts the items by their last creation time in ascending order, meaning the least recently created items will be displayed first.
  | 'random'; // Items are ordered randomly.

type BlazeAdvancedOrderType =
  'LiveFirst'; // Live content is displayed first.

export type BlazeDataSourcePersonalizedType =
  BlazeDataSourcePersonalizedType_Ids
  | BlazeDataSourcePersonalizedType_Labels;

/**
* Personalized content based on specific content type IDs.
*/
interface BlazeDataSourcePersonalizedType_Ids {
  type: 'Ids'

  ids: Partial<Record<BlazeDataSourcePersonalizedTypeContentType, string[]>>;
}

/**
 * Personalized content based on label filtering and priority.
 */
interface BlazeDataSourcePersonalizedType_Labels {
  type: 'Labels';

  /** 
  * Mandatory filter expression that defines which content is considered.  
  */
  labelsFilter: BlazeWidgetLabel;

  /**
  * Mandatory array of `BlazeWidgetLabel` to define the sorting priority for the labels.
  */
  labelsPriority: BlazeWidgetLabel[];
}

type BlazeDataSourcePersonalizedTypeContentType =
  'players' // Use player IDs for personalization.
  | 'teams'; // Use team IDs for personalization.

// Widget-specific parameter interfaces
export interface BlazeWidgetOnItemClickedParams {
  sourceId?: string;
  widgetItemId: string;
  widgetItemTitle?: string;
}

// Widget delegate interface that extends the base player delegate
export interface BlazeWidgetDelegate extends BlazeBasePlayerDelegate {
  // Widget-specific methods
  onItemClicked?: (params: BlazeWidgetOnItemClickedParams) => void;
}