import axios from 'axios';
import { API_URL_ADDITIONAL_SERVICE } from '@/shared/api/api-url-additional-service';
import { resultify } from '@/shared/lib/resultify';
import { NiceAxiosError } from '@/shared/@types/error';
import {
  ExtensionAlimtalkListParams,
  ExtensionAlimtalkListResponse
} from '../../model/alimtalk/types';
import {
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';
import { getHeaderUserAgent } from '@/shared/constants/url';

export const extensionAlimtalkList = (params: ExtensionAlimtalkListParams) => {
  let headerOptions = {
    menuId: 58,
    apiType: 'SELECT'
  };
  let options = {
    headers: {
      'X-User-Agent': getHeaderUserAgent(headerOptions)
    }
  };
  return resultify(
    axios.post<ExtensionAlimtalkListResponse>(API_URL_ADDITIONAL_SERVICE.extensionAlimtalkList(), params, options),
  );
};

export const useExtensionAlimtalkListMutation = (options?: UseMutationOptions<ExtensionAlimtalkListResponse, NiceAxiosError, ExtensionAlimtalkListParams>) => {
  const mutation = useMutation<ExtensionAlimtalkListResponse, NiceAxiosError, ExtensionAlimtalkListParams>({
    ...options,
    mutationFn: (params: ExtensionAlimtalkListParams) => extensionAlimtalkList(params),
  });

  return {
    ...mutation,
  };
};
