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 {
  ExtensionAlimtalkDetailParams,
  ExtensionAlimtalkDetailResponse
} from '../../model/alimtalk/types';
import {
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';
import { getHeaderUserAgent } from '@/shared/constants/url';

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

export const useExtensionAlimtalkDetailMutation = (options?: UseMutationOptions<ExtensionAlimtalkDetailResponse, NiceAxiosError, ExtensionAlimtalkDetailParams>) => {
  const mutation = useMutation<ExtensionAlimtalkDetailResponse, NiceAxiosError, ExtensionAlimtalkDetailParams>({
    ...options,
    mutationFn: (params: ExtensionAlimtalkDetailParams) => extensionAlimtalkDetail(params),
  });

  return {
    ...mutation,
  };
};
