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 { 
  ChangePasswordParams,
  ChangePasswordResponse
} from '../model/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';

export const userChangePassword = (params: ChangePasswordParams) => {
  return resultify(
    axios.post<ChangePasswordResponse>(API_URL_USER.changePassword(), params),
  );
};

export const useUserChangePasswordMutation = (options?: UseMutationOptions<ChangePasswordResponse, CBDCAxiosError, ChangePasswordParams>) => {
  const mutation = useMutation<ChangePasswordResponse, CBDCAxiosError, ChangePasswordParams>({
    ...options,
    mutationFn: (params: ChangePasswordParams) => userChangePassword(params),
  });

  return {
    ...mutation,
  };
};
