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

export const userChangeCancelPassword = (params: ChangeCancelPasswordParams) => {
  return resultify(
    axios.post<ChangeCancelPasswordResponse>(API_URL_USER.userChangeCancelPassword(), params),
  );
};

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

  return {
    ...mutation,
  };
};
