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

import { chatQueryKeys } from '../chat-query-keys';
import { chatApi } from '../chat-api';

import type { BaseAxiosError } from '../../../../types';
import { ResponseType } from '@api/response-type';

export const usePostSetGroupAdminMutation = () => {
  return useMutation<
    ResponseType,
    BaseAxiosError,
    { token: string; uid: number; group_token: string; value: 0 | 1 },
    ResponseType
  >({
    mutationKey: chatQueryKeys.setGroupAdmin(),
    mutationFn: async (data) => {
      const response = await chatApi.setGroupAdmin(
        data.token,
        data.uid,
        data.group_token,
        data.value
      );
      return response.data;
    }
  });
};
