import { useQuery } from 'react-query';

import { eventsKeys } from 'src/pages/dashboard/events/queries';
import { getEvents } from 'src/services/events';
import { EventTimeRange, InvitationStatus } from 'src/types/events';

type UseEventsProps = {
  pagination: { limit: number; page: number };
  timeRange: EventTimeRange;
  onlyInvited: boolean;
  invitationStatus?: InvitationStatus[];
  useQueryOptions?;
  onlyCreatedByUser?: boolean;
};

export const useEvents = ({
  pagination,
  timeRange,
  onlyInvited,
  useQueryOptions,
  invitationStatus,
  onlyCreatedByUser,
}: UseEventsProps) => {
  return useQuery(
    eventsKeys.eventsList(
      pagination,
      timeRange,
      invitationStatus,
      onlyInvited,
      onlyCreatedByUser,
    ),
    () =>
      getEvents(
        pagination,
        timeRange,
        invitationStatus,
        onlyInvited,
        onlyCreatedByUser,
      ),
    useQueryOptions,
  );
};

export default useEvents;
