import axios from 'axios';
import { API_URL_USER } from '@/shared/api/api-url-user';
import { resultify } from '@/shared/lib/resultify';
import { NiceAxiosError } from '@/shared/@types/error';
import { 
  ChangeCancelPasswordParams,
  ChangeCancelPasswordResponse
} from '../model/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';
import { getHeaderUserAgent } from '@/shared/constants/url';

export const userChangeCancelPassword = (params: ChangeCancelPasswordParams) => {
  let headerOptions = {
    menuId: 46,
    apiType: 'UPDATE'
  };
  let options = {
    headers: {
      'X-User-Agent': getHeaderUserAgent(headerOptions)
    }
  };
  return resultify(
    axios.post<ChangeCancelPasswordResponse>(API_URL_USER.userChangeCancelPassword(), params, options),
  );
};

export const useUserChangeCancelPasswordMutation = (options?: UseMutationOptions<ChangeCancelPasswordResponse, NiceAxiosError, ChangeCancelPasswordParams>) => {
  const mutation = useMutation<ChangeCancelPasswordResponse, NiceAxiosError, ChangeCancelPasswordParams>({
    ...options,
    mutationFn: (params: ChangeCancelPasswordParams) => userChangeCancelPassword(params),
  });

  return {
    ...mutation,
  };
};
