import axios from 'axios';
import { API_URL_MERCHANT } from '@/shared/api/api-url-merchant';
import { resultify } from '@/shared/lib/resultify';
import { NiceAxiosError } from '@/shared/@types/error';
import { 
  MerchantMidStatusParams,
  MerchantMidStatusResponse
} from '../model/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';
import { getHeaderUserAgent } from '@/shared/constants/url';

export const merchantMidStatus = (params: MerchantMidStatusParams) => {
  let headerOptions = {
    menuId: 40,
    apiType: 'SELECT'
  };
  let options = {
    headers: {
      'X-User-Agent': getHeaderUserAgent(headerOptions)
    }
  };
  return resultify(
    axios.post<MerchantMidStatusResponse>(API_URL_MERCHANT.merchantMidStatus(params.mid), params, options),
  );
};

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

  return {
    ...mutation,
  };
};
