import {
  type CollaboratorSurveysReqParams,
  type DimensionsParams,
  type EnpsChartParams,
  type EnpsScoresParams,
  type FavDimensionIndexStatsParams,
  type FavDimensionStatsParams,
  type FavListIndexParams,
  type FavQuestionsStatsParams,
  type GetQuestionsParams,
  type HeatmapReqParams,
  type HeatmapScoresReqParams,
  type ManagerSurvey,
  type ManagerSurveysParams,
  type ParticipationListParams,
  type QuestionAnswersParams,
  type QuestionStatsParams,
  type SegmentId,
  type SegmentType,
} from './types';

export const pxKeys = {
  all: () => ['people-experience'],
  collaboratorSurveysBase: () => [...pxKeys.all(), 'surveys'],
  collaboratorSurveysList: (params: CollaboratorSurveysReqParams) => [
    ...pxKeys.collaboratorSurveysBase(),
    params,
  ],
  surveyDetail: (surveyId: ManagerSurvey['id']) => [
    ...pxKeys.collaboratorSurveysBase(),
    surveyId,
  ],
  managerSurveyDetail: (surveyId: ManagerSurvey['id']) => [
    ...pxKeys.collaboratorSurveysBase(),
    'manager',
    surveyId,
  ],
  managerSurveys: (params: ManagerSurveysParams) => [
    ...pxKeys.collaboratorSurveysBase(),
    'manager',
    params,
  ],
  managerParticipation: ({
    surveyId,
    depth,
    ...other
  }: ParticipationListParams) => [
    ...pxKeys.surveyDetail(surveyId),
    'manager-participation',
    depth,
    other,
  ],
  participationStats: (surveyId: ManagerSurvey['id']) => [
    ...pxKeys.surveyDetail(surveyId),
    'participation',
  ],
  heatmapScores: ({ surveyId, ...params }: HeatmapScoresReqParams) => [
    ...pxKeys.surveyDetail(surveyId),
    'heatmap',
    'scores',
    params,
  ],
  heatmapTotals: ({ surveyId, ...params }: HeatmapReqParams) => [
    ...pxKeys.surveyDetail(surveyId),
    'heatmap',
    'total',
    params,
  ],
  segmentDropdownItems: ({ surveyId }: { surveyId: ManagerSurvey['id'] }) => [
    ...pxKeys.surveyDetail(surveyId),
    'segment-dropdown-items',
  ],
  segmentationGroups: (surveyId: ManagerSurvey['id']) => [
    ...pxKeys.surveyDetail(surveyId),
    'segmentation-groups',
  ],
  eNpsScores: ({ surveyId, ...params }: EnpsScoresParams) => [
    ...pxKeys.surveyDetail(surveyId),
    'enps-scores',
    params,
  ],
  eNpsScoresDiff: (
    surveyId: ManagerSurvey['id'],
    comparedSurvey: number | undefined,
  ) => [...pxKeys.surveyDetail(surveyId), 'enps-scores', { comparedSurvey }],
  questionAnalytics: (params: QuestionStatsParams) => [
    ...pxKeys.all(),
    'analytics',
    params,
  ],
  questionStats: (params: QuestionStatsParams) => [
    ...pxKeys.questionAnalytics(params),
    'stats',
  ],
  questionAnswers: (params: QuestionAnswersParams) => [
    ...pxKeys.questionAnalytics(params),
    'answers',
  ],
  infiniteQuestionAnswers: (params: QuestionAnswersParams) => [
    ...pxKeys.questionAnalytics(params),
    'infinite-answers',
  ],
  topics: () => [...pxKeys.all(), 'topics'],
  filteredTopics: (params: DimensionsParams) => [...pxKeys.topics(), params],
  eNpsChart: ({
    surveyId,
    dimension,
    parentId,
    ...params
  }: EnpsChartParams) => [
    ...pxKeys.all(),
    'surveys',
    'work-environment-survey',
    surveyId,
    'analytics',
    'nps-segments',
    { dimension, parentId, ...params },
  ],
  eNpsChartCompared: (
    surveyId: ManagerSurvey['id'],
    dimension: SegmentType,
    comparedSurvey: number | undefined,
    parentId?: SegmentId | undefined,
  ) => [
    ...pxKeys.all(),
    'surveys',
    'work-environment-survey',
    surveyId,
    'analytics',
    'nps-segments',
    { dimension, comparedSurvey, parentId },
  ],
  favListIndexStats: ({ surveyId, ...params }: FavListIndexParams) => [
    ...pxKeys.surveyDetail(surveyId),
    'analytics',
    'favorability-stats',
    'list-index',
    params,
  ],
  favDimensionIndexStats: ({
    surveyId,
    ...params
  }: FavDimensionIndexStatsParams) => [
    ...pxKeys.surveyDetail(surveyId),
    'analytics',
    'favorability-stats',
    'dimension-index',
    params,
  ],
  favQuestionsStats: ({ surveyId, ...params }: FavQuestionsStatsParams) => [
    ...pxKeys.surveyDetail(surveyId),
    'analytics',
    'favorability-stats',
    'questions',
    params,
  ],
  favDimensionStats: ({ surveyId, ...params }: FavDimensionStatsParams) => [
    ...pxKeys.surveyDetail(surveyId),
    'analytics',
    'favorability-stats',
    'dimension',
    params,
  ],
  questions: (params: GetQuestionsParams) => [
    ...pxKeys.all(),
    'survey-questions',
    params,
  ],
  infiniteSegmentationGroups: (surveyId: ManagerSurvey['id']) => [
    ...pxKeys.surveyDetail(surveyId),
    'infinite-segmentation-groups',
  ],
  segmentationItems: ({
    surveyId,
    groupId,
    searchText,
  }: {
    surveyId: ManagerSurvey['id'];
    groupId: number;
    searchText: string;
  }) => [
    ...pxKeys.surveyDetail(surveyId),
    'segmentation-items',
    groupId,
    searchText,
  ],
};
