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

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

export const useSettlementsCalendarMutation = (options?: UseMutationOptions<SettlementsCalendarResponse, NiceAxiosError, SettlementsCalendarParams>) => {
  const mutation = useMutation<SettlementsCalendarResponse, NiceAxiosError, SettlementsCalendarParams>({
    ...options,
    mutationFn: (params: SettlementsCalendarParams) => settlementsCalendar(params),
  });

  return {
    ...mutation,
  };
};
