import {
  PDPAttributes as ApiPDPAttributes,
  PLPAttributes as ApiPLPAttributes,
  QueryTypedAttributes as ApiQueryTypedAttributes,
  SearchAttributes as ApiSearchAttributes,
  SuggestionClickedAttributes as ApiSuggestionClickedAttributes,
  UserEvent as ApiUserEvent,
  FormType,
  PageVisitCategory,
  UserEventCategory,
} from '@spiffy-ai/commerce-api-client';
import { CamelCasedPropertiesDeep } from 'src/application/models/utilityTypes';

// TODO flatten these out or explore new typescript openapi generator fork
export interface PDPAttributes extends CamelCasedPropertiesDeep<ApiPDPAttributes> {}

export interface PLPAttributes extends CamelCasedPropertiesDeep<ApiPLPAttributes> {}

export interface SearchAttributes extends CamelCasedPropertiesDeep<ApiSearchAttributes> {}

export interface QueryTypedAttributes extends CamelCasedPropertiesDeep<ApiQueryTypedAttributes> {
  userTyped?: boolean;
}

export interface FormSubmittedAttributes {
  filledSchema: Record<string, unknown>;
  formResponseId: string;
  formType: FormType;
}

export interface PageVisitAttributes {
  url: string;
  pageVisitCategory: PageVisitCategory;
}

export interface SuggestionClickedAttributes extends CamelCasedPropertiesDeep<ApiSuggestionClickedAttributes> {
  content?: string;
}

export type UserEventAttributes =
  | PDPAttributes
  | PLPAttributes
  | QueryTypedAttributes
  | SearchAttributes
  | SuggestionClickedAttributes
  | PageVisitAttributes;

export interface PDPUserEvent {
  category: UserEventCategory.PdpVisit | UserEventCategory.AddToCart;
  attributes: PDPAttributes;
}

export interface PLPUserEvent {
  category: UserEventCategory.PlpVisit;
  attributes: PLPAttributes;
}

export interface QueryTypedUserEvent {
  category: UserEventCategory.QueryTyped;
  attributes: QueryTypedAttributes;
}

export interface SearchUserEvent {
  category: UserEventCategory.Search;
  attributes: SearchAttributes;
}

export interface SuggestionsClickedUserEvent {
  category: UserEventCategory.SuggestionClicked;
  attributes: SuggestionClickedAttributes;
}

export interface AppLoadedUserEvent {
  category: UserEventCategory.AppLoaded;
}

export interface AppUnloadedEvent {
  category: UserEventCategory.AppUnloaded;
}

export interface PageVisitEvent {
  category: UserEventCategory.PageVisit;
  attributes: PageVisitAttributes;
}

export interface FormSubmitted {
  category: UserEventCategory.FormSubmitted;
  attributes: FormSubmittedAttributes;
}

export type UserEvent = CamelCasedPropertiesDeep<
  Pick<ApiUserEvent, 'event_id' | 'category' | 'created_at'>
> &
  (
    | SuggestionsClickedUserEvent
    | AppLoadedUserEvent
    | PDPUserEvent
    | QueryTypedUserEvent
    | SearchUserEvent
    | AppUnloadedEvent
    | PLPUserEvent
    | PageVisitEvent
    | FormSubmitted
  );
