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

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

export const useExtensionAlimtalkSettingDetailMutation = (options?: UseMutationOptions<ExtensionAlimtalkSettingDetailResponse, NiceAxiosError, ExtensionAlimtalkSettingDetailParams>) => {
  const mutation = useMutation<ExtensionAlimtalkSettingDetailResponse, NiceAxiosError, ExtensionAlimtalkSettingDetailParams>({
    ...options,
    mutationFn: (params: ExtensionAlimtalkSettingDetailParams) => extensionAlimtalkSettingDetail(params),
  });

  return {
    ...mutation,
  };
};
