import { type PaginationParams } from 'src/utils/pagination';

export const goalsKeys = {
  all: ['goals'] as const,

  lists: () => [...goalsKeys.all, 'list'] as const,
  myGoalsList: (
    goalCycleId: number,
    q: string,
    pagination?: PaginationParams,
  ) =>
    pagination
      ? ([
          ...goalsKeys.lists(),
          'my-goals',
          goalCycleId,
          q,
          pagination,
        ] as const)
      : ([...goalsKeys.lists(), 'my-goals', goalCycleId, q] as const),
  teamList: (
    goalCycleId: number,
    query: string | Record<string, unknown>,
    pagination?: PaginationParams,
  ) =>
    pagination
      ? ([
          ...goalsKeys.lists(),
          'team',
          goalCycleId,
          query,
          pagination,
        ] as const)
      : ([...goalsKeys.lists(), 'team', goalCycleId, query] as const),
  generalList: (goalCycleId: number, pagination: PaginationParams) =>
    [...goalsKeys.lists(), 'general', goalCycleId, pagination] as const,

  details: () => [...goalsKeys.all, 'detail'] as const,
  detail: (id: number | null) => [...goalsKeys.details(), id] as const,

  histories: (goalId: number) =>
    [...goalsKeys.detail(goalId), 'history'] as const,
  history: (goalId: number, params?: Record<string, unknown>) =>
    params
      ? ([...goalsKeys.histories(goalId), params] as const)
      : goalsKeys.histories(goalId),

  responsibleSubordinates: (userId: number) =>
    [...goalsKeys.all, 'responsible-subordinates', userId] as const,

  cycles: (pagination: PaginationParams) =>
    ['goal-cycles', pagination] as const,
  cycle: (goalCycleId: number) => ['goal-cycles', goalCycleId] as const,
  allStats: (goalCycleId: number) =>
    ['goal-cycles', goalCycleId, 'stats'] as const,
  allConfiguration: () => ['goal-cycles', 'configuration'] as const,
  weights: (goalCycleId: number, userId: number) =>
    [
      'goal-cycles',
      goalCycleId,
      'owner',
      userId,
      'weights-with-weighted-progress',
    ] as const,

  allFormulas: () => ['goalFormulas'] as const,
  formulas: (pagination: PaginationParams, search: string) =>
    [...goalsKeys.allFormulas(), { ...pagination, search }] as const,
  allRangeFields: (formulaChainId?: number) =>
    ['goal-formulas', formulaChainId ?? null, 'range-fields'] as const,
};
