import { useQuery } from '@tanstack/react-query';
import { useMutation } from '@tanstack/react-query';

import { seriesQueryKeys } from '../series-query-keys';
import { seriesApi, type PostSetToggleItemReturn, type PostSetToggleItem } from '../series-api';

import type { BaseAxiosError } from '../../../../types';

export const usePostSetToggleItem = () => {
  return useMutation<
    PostSetToggleItemReturn,
    BaseAxiosError,
    { token: string; series_id: number; item_id: number; checked: 0 | 1; double: 0 | 1 },
    PostSetToggleItemReturn
  >({
    mutationKey: seriesQueryKeys.setToggleItem(),
    mutationFn: async (variables) => {
      const response = await seriesApi.setToggleItem(
        variables.token,
        variables.series_id,
        variables.item_id,
        variables.checked,
        variables.double
      );
      return response.data;
    }
  });
};
