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 usePostSetPinGroupMessageMutation = () => {
  return useMutation<
    ResponseType,
    BaseAxiosError,
    { token: string; message_id: number; group_token: string; pin: 0 | 1 },
    ResponseType
  >({
    mutationKey: chatQueryKeys.setPinGroupMessage(),
    mutationFn: async (data) => {
      const response = await chatApi.setPinGroupMessage(
        data.token,
        data.message_id,
        data.group_token,
        data.pin
      );
      return response.data;
    }
  });
};
