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

export const merchantMidStatus = (params: MerchantMidStatusParams) => {
  return resultify(
    axios.post<MerchantMidStatusResponse>(API_URL_MERCHANT.merchantMidStatus(params.mid), params),
  );
};

export const useMerchantMidStatusMutation = (options?: UseMutationOptions<MerchantMidStatusResponse, CBDCAxiosError, MerchantMidStatusParams>) => {
  const mutation = useMutation<MerchantMidStatusResponse, CBDCAxiosError, MerchantMidStatusParams>({
    ...options,
    mutationFn: (params: MerchantMidStatusParams) => merchantMidStatus(params),
  });

  return {
    ...mutation,
  };
};
