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 { 
  SettlementsTransactionListParams,
  SettlementsTransactionListResponse
} from '../model/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';
import { getHeaderUserAgent } from '@/shared/constants/url';

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

export const useSettlementsTransactionListMutation = (options?: UseMutationOptions<SettlementsTransactionListResponse, NiceAxiosError, SettlementsTransactionListParams>) => {
  const mutation = useMutation<SettlementsTransactionListResponse, NiceAxiosError, SettlementsTransactionListParams>({
    ...options,
    mutationFn: (params: SettlementsTransactionListParams) => settlementsTransactionList(params),
  });

  return {
    ...mutation,
  };
};
