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

export const userFind = (params: UserFindParams) => {
  return resultify(
    axios.post<UserFindResponse>(API_URL_USER.findUser(), params),
  );
};

export const useUserFindMutation = (options?: UseMutationOptions<UserFindResponse, CBDCAxiosError, UserFindParams>) => {
  const mutation = useMutation<UserFindResponse, CBDCAxiosError, UserFindParams>({
    ...options,
    mutationFn: (params: UserFindParams) => userFind(params),
  });

  return {
    ...mutation,
  };
};
