import axios from 'axios';
import { API_URL } from '@/shared/api/urls';
import { resultify } from '@/shared/lib/resultify';
import { CBDCAxiosError } from '@/shared/@types/error';
import { 
  QnaSaveParams,
  QnaSaveResponse
} from '../model/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';

export const qnaSave = (params: QnaSaveParams) => {
  return resultify(
    axios.post<QnaSaveResponse>(API_URL.qnaSave(), params),
  );
};

export const useQnaSaveMutation = (options?: UseMutationOptions<QnaSaveResponse, CBDCAxiosError, QnaSaveParams>) => {
  const mutation = useMutation<QnaSaveResponse, CBDCAxiosError, QnaSaveParams>({
    ...options,
    mutationFn: (params: QnaSaveParams) => qnaSave(params),
  });

  return {
    ...mutation,
  };
};
