import { EnviveMetricsEventName, SpiffyMetricsEventName } from '../../contexts/amplitudeContext';

export interface WidgetInteractionContext {
  page_type: WidgetInteractionPageType;
  page_id: string;
}

export interface WidgetInteractionTrigger {
  interaction_id?: string;
  widget: WidgetInteractionComponent;
  widget_interaction: WidgetInteractionType;
  widget_interaction_data?: WidgetInteractionData | null;
  interaction_class?: InteractionClass;
}

export interface InternalWidgetInteraction {
  eventName: SpiffyMetricsEventName | EnviveMetricsEventName;
  context: WidgetInteractionContext;
  trigger: WidgetInteractionTrigger;
}

export interface WidgetInteraction {
  eventName: InternalWidgetInteraction['eventName'];
  trigger: InternalWidgetInteraction['trigger'];
}

export enum WidgetInteractionPageType {
  PDP = 'pdp',
  PLP = 'plp',
  HOMEPAGE = 'homepage',
  SEARCH = 'search',
  OTHER = 'other',
  FULL_PAGE = 'full_page',
}

export enum WidgetInteractionComponent {
  EMBEDDED_WIDGET = 'embedded_widget',
  SUGGESTION_BAR = 'suggestion_bar',
  FLOATING_BUTTON = 'floating_button',
  FULL_PAGE_SALES_AGENT = 'full_page_sales_agent',
  SOCIAL_PROOF = 'social_proof',
  CHAT_PREVIEW = 'chat_preview',
  FLOATING_CHAT = 'floating_chat',
  SINGLE_IMAGE_PROMPT = 'single_image_prompt',
  IMAGE_PROMPT_CARD = 'image_prompt_card',
  POST_INTERACTION_COMPARISON = 'post_interaction_comparison',
  POST_INTERACTION_EMBEDDED = 'post_interaction_embedded',
}

export enum WidgetInteractionType {
  QUERY_INPUT_CLICKED = 'query_input_clicked',
  SUGGESTION_CLICKED = 'suggestion_clicked',
  WIDGET_CLICKED = 'widget_clicked',
  WIDGET_HOVERED = 'widget_hovered',
  WIDGET_EXPANDED = 'widget_expanded',
  WIDGET_COLLAPSED = 'widget_collapsed',
  SUGGESTION_SCROLLED = 'suggestion_scrolled',
  LINK_CLICKED = 'link_clicked',
  PRODUCT_CARD_CLICKED = 'product_card_clicked',
  TEXT_LINK_CLICKED = 'text_link_clicked',
  ARTICLE_LINK_CLICKED = 'article_link_clicked',
  REVIEW_CARD_CLICKED = 'review_card_clicked',
  MESSAGE_SUBMITTED = 'message_submitted',
  MANUAL_SCROLL_TO_BOTTOM = 'manual_scroll_to_bottom',
  VOICE_TRANSCRIPTION_STARTED = 'voice_transcription_started',
  VOICE_TRANSCRIPTION_COMPLETED = 'voice_transcription_completed',
  OVERLAY_DISMISSED = 'overlay_dismissed',
}

export enum InteractionClass {
  PASSIVE = 'passive', // No user commitment — hover, scroll, visibility triggers
  NAVIGATIONAL = 'navigational', // Opens/closes something — often a side effect of intent
  INTENTIONAL = 'intentional', // Deliberate user action — clicks, submits, typed queries
}

export const INTERACTION_TYPE_CLASS: Record<WidgetInteractionType, InteractionClass> = {
  [WidgetInteractionType.QUERY_INPUT_CLICKED]: InteractionClass.INTENTIONAL,
  [WidgetInteractionType.SUGGESTION_CLICKED]: InteractionClass.INTENTIONAL,
  [WidgetInteractionType.WIDGET_CLICKED]: InteractionClass.INTENTIONAL,
  [WidgetInteractionType.WIDGET_HOVERED]: InteractionClass.PASSIVE,
  [WidgetInteractionType.WIDGET_EXPANDED]: InteractionClass.NAVIGATIONAL,
  [WidgetInteractionType.WIDGET_COLLAPSED]: InteractionClass.NAVIGATIONAL,
  [WidgetInteractionType.SUGGESTION_SCROLLED]: InteractionClass.PASSIVE,
  [WidgetInteractionType.LINK_CLICKED]: InteractionClass.INTENTIONAL,
  [WidgetInteractionType.PRODUCT_CARD_CLICKED]: InteractionClass.INTENTIONAL,
  [WidgetInteractionType.TEXT_LINK_CLICKED]: InteractionClass.INTENTIONAL,
  [WidgetInteractionType.ARTICLE_LINK_CLICKED]: InteractionClass.INTENTIONAL,
  [WidgetInteractionType.REVIEW_CARD_CLICKED]: InteractionClass.INTENTIONAL,
  [WidgetInteractionType.MESSAGE_SUBMITTED]: InteractionClass.INTENTIONAL,
  [WidgetInteractionType.MANUAL_SCROLL_TO_BOTTOM]: InteractionClass.PASSIVE,
  [WidgetInteractionType.VOICE_TRANSCRIPTION_STARTED]: InteractionClass.INTENTIONAL,
  [WidgetInteractionType.VOICE_TRANSCRIPTION_COMPLETED]: InteractionClass.INTENTIONAL,
  [WidgetInteractionType.OVERLAY_DISMISSED]: InteractionClass.NAVIGATIONAL,
};

export type URL = {
  url: string;
};

export type Product = {
  product_id: string;
};

export type Review = {
  review_id: string;
};

export type Suggestion = {
  suggestion_id: string;
};

export type Request = {
  request_text: string;
};

export type Collapse = {
  collapse_source: 'close_button' | 'swipe' | 'body_click';
};

export type SuggestionScrolled = {
  suggestion_scrolled: Suggestion;
};

export type SuggestionClicked = {
  suggestion_clicked: Suggestion;
};

export type SuggestionHovered = {
  suggestion_hovered: Suggestion;
};

export type LinkClicked = {
  link_clicked: URL;
};

export type WidgetCollapsed = {
  widget_collapsed: Collapse;
};

export type TextLinkClicked = {
  text_link_clicked: URL;
};

export type ArticleLinkClicked = {
  article_link_clicked: URL;
};

export type ProductCardClicked = {
  product_card_clicked: Product;
};

export type ReviewCardClicked = {
  review_card_clicked: Review;
};

export type MessageSubmitted = {
  message_submitted: Request;
};

export type VoiceTranscription = {
  transcription: string;
};

export type WidgetInteractionData =
  | SuggestionScrolled
  | SuggestionClicked
  | SuggestionHovered
  | LinkClicked
  | WidgetCollapsed
  | TextLinkClicked
  | ArticleLinkClicked
  | ProductCardClicked
  | ReviewCardClicked
  | MessageSubmitted
  | VoiceTranscription;
