import axios from 'axios';
import { API_URL_SUPPORT } from '@/shared/api/api-url-support';
import { resultify } from '@/shared/lib/resultify';
import { CBDCAxiosError } from '@/shared/@types/error';
import { 
  QnaListParams,
  QnaListResponse
} from '../model/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';

export const qnaList = (params: QnaListParams) => {
  return resultify(
    axios.post<QnaListResponse>(API_URL_SUPPORT.qnaList(), params),
  );
};

export const useQnaListMutation = (options?: UseMutationOptions<QnaListResponse, CBDCAxiosError, QnaListParams>) => {
  const mutation = useMutation<QnaListResponse, CBDCAxiosError, QnaListParams>({
    ...options,
    mutationFn: (params: QnaListParams) => qnaList(params),
  });

  return {
    ...mutation,
  };
};
