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

import { type AxiosResponse } from 'axios';

import { pxKeys } from '../queries';
import { getManagerParticipation } from '../services';
import {
  type ManagerParticipationResponse,
  type ParticipationListParams,
} from '../types';

type CustomOptions = UseQueryOptions<
  AxiosResponse<ManagerParticipationResponse, any>,
  unknown,
  ManagerParticipationResponse,
  any[]
>;

const useManagerParticipation = ({
  depth,
  queryOptions,
  ...other
}: ParticipationListParams & { queryOptions?: CustomOptions }) => {
  const query = useQuery(
    pxKeys.managerParticipation({ depth, ...other }),
    () => getManagerParticipation(other),
    {
      select: res => res.data,
      ...queryOptions,
    },
  );

  return query;
};

export default useManagerParticipation;
