import axios from 'axios';
import { API_URL_ADDITIONAL_SERVICE } from '@/shared/api/api-url-additional-service';
import { resultify } from '@/shared/lib/resultify';
import { CBDCAxiosError } from '@/shared/@types/error';
import { 
  ExtensionAlimtalkSettingSaveParams,
  ExtensionAlimtalkSettingSaveResponse
} from '../../model/alimtalk/types';

import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';

export const extensionAlimtalkSettingSave = (params: ExtensionAlimtalkSettingSaveParams) => {
  return resultify(
    axios.post<ExtensionAlimtalkSettingSaveResponse>(API_URL_ADDITIONAL_SERVICE.extensionAlimtalkSettingSave(), params),
  );
};

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

  return {
    ...mutation,
  };
};
