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

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

export const useExtensionAlimtalkSettingSaveMutation = (options?: UseMutationOptions<ExtensionAlimtalkSettingSaveResponse, NiceAxiosError, ExtensionAlimtalkSettingSaveParams>) => {
  const mutation = useMutation<ExtensionAlimtalkSettingSaveResponse, NiceAxiosError, ExtensionAlimtalkSettingSaveParams>({
    ...options,
    mutationFn: (params: ExtensionAlimtalkSettingSaveParams) => extensionAlimtalkSettingSave(params),
  });

  return {
    ...mutation,
  };
};
