import axios from 'axios';
import { API_URL } from '@/shared/api/urls';
import { resultify } from '@/shared/lib/resultify';
import { CBDCAxiosError } from '@/shared/@types/error';
import { 
  UserCreateParams,
  UserCreateResponse
} from '../model/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';

export const userCreate = (params: UserCreateParams) => {
  return resultify(
    axios.post<UserCreateResponse>(API_URL.userCreate(), params),
  );
};

export const useUserCreateMutation = (options?: UseMutationOptions<UserCreateResponse, CBDCAxiosError, UserCreateParams>) => {
  const mutation = useMutation<UserCreateResponse, CBDCAxiosError, UserCreateParams>({
    ...options,
    mutationFn: (params: UserCreateParams) => userCreate(params),
  });

  return {
    ...mutation,
  };
};
