import { type UseQueryOptions, useQuery } from 'react-query';

import { type AxiosResponse } from 'axios';

import { getStates } from 'src/pages/dashboard/serviceManagement/services';
import {
  ServiceItemTypes,
  type State,
} from 'src/pages/dashboard/serviceManagement/types';

import { serviceManagementKeys } from '../queries';

const useTaskStates = (
  taskType: ServiceItemTypes = ServiceItemTypes.INCIDENT,
  options?: Omit<
    UseQueryOptions<AxiosResponse<State[], any>, any, State[]>,
    'queryKey' | 'queryFn'
  >,
) => {
  return useQuery<AxiosResponse<State[], any>, any, State[]>(
    serviceManagementKeys.states.all(taskType),
    () => getStates(taskType),
    {
      select: (response: AxiosResponse<State[], any>) => response.data,
      ...options,
    },
  );
};

export default useTaskStates;
