import axios from 'axios';
import { API_URL_MERCHANT } from '@/shared/api/api-url-merchant';
import { resultify } from '@/shared/lib/resultify';
import { CBDCAxiosError } from '@/shared/@types/error';
import { 
  MerchantMidParams,
  MerchantMidResponse
} from '../model/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';

export const merchantMid = (params: MerchantMidParams) => {
  return resultify(
    axios.post<MerchantMidResponse>(API_URL_MERCHANT.merchantMid(params.mid), params),
  );
};

export const useMerchantMidMutation = (options?: UseMutationOptions<MerchantMidResponse, CBDCAxiosError, MerchantMidParams>) => {
  const mutation = useMutation<MerchantMidResponse, CBDCAxiosError, MerchantMidParams>({
    ...options,
    mutationFn: (params: MerchantMidParams) => merchantMid(params),
  });

  return {
    ...mutation,
  };
};
