import axios from 'axios';
import { API_URL_SETTLEMENT } from '@/shared/api/api-url-settlement';
import { resultify } from '@/shared/lib/resultify';
import { NiceAxiosError } from '@/shared/@types/error';
import { 
  SettlementsHistoryDetailParams,
  SettlementsHistoryDetailResponse
} from '../model/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';
import { getHeaderUserAgent } from '@/shared/constants/url';

export const settlementsHistoryDetail = (params: SettlementsHistoryDetailParams) => {
  let headerOptions = {
    menuId: 37,
    apiType: 'SELECT'
  };
  let options = {
    headers: {
      'X-User-Agent': getHeaderUserAgent(headerOptions)
    }
  };
  return resultify(
    axios.post<SettlementsHistoryDetailResponse>(API_URL_SETTLEMENT.settlementsHistoryDetail(), params, options),
  );
};

export const useSettlementsHistoryDetailMutation = (options?: UseMutationOptions<SettlementsHistoryDetailResponse, NiceAxiosError, SettlementsHistoryDetailParams>) => {
  const mutation = useMutation<SettlementsHistoryDetailResponse, NiceAxiosError, SettlementsHistoryDetailParams>({
    ...options,
    mutationFn: (params: SettlementsHistoryDetailParams) => settlementsHistoryDetail(params),
  });

  return {
    ...mutation,
  };
};
