import { VariantTypeEnum } from 'src/application/models';
import {
  FullPageSalesAgentVariantInfo,
  HomeVariantInfo,
  OtherVariantInfo,
  PDPPageVariantInfo,
  PLPPageVariantInfo,
  PageVariantInfo,
} from '../../contexts/pageContext/types';
import { WidgetInteractionContext, WidgetInteractionPageType } from './types';

export const extractPageContext = (
  pageVariant: PageVariantInfo,
): WidgetInteractionContext | null => {
  switch (pageVariant.variantType) {
    case VariantTypeEnum.Pdp:
      return {
        page_id: (pageVariant as PDPPageVariantInfo).productId,
        page_type: WidgetInteractionPageType.PDP,
      };
    case VariantTypeEnum.Plp:
      return {
        page_id: (pageVariant as PLPPageVariantInfo).plpId,
        page_type: WidgetInteractionPageType.PLP,
      };
    case VariantTypeEnum.Home:
      return {
        page_id: (pageVariant as HomeVariantInfo).url,
        page_type: WidgetInteractionPageType.HOMEPAGE,
      };
    case VariantTypeEnum.Other:
      return {
        page_id: (pageVariant as OtherVariantInfo).url,
        page_type: WidgetInteractionPageType.OTHER,
      };
    case VariantTypeEnum.FullPageSalesAgent:
      return {
        page_id: (pageVariant as FullPageSalesAgentVariantInfo).url,
        page_type: WidgetInteractionPageType.FULL_PAGE,
      };
    default:
      return null;
  }

  return null;
};
