import axios from 'axios';
import { API_URL_SETTLEMENT } from '@/shared/api/api-url-settlement';
import { resultify } from '@/shared/lib/resultify';
import { CBDCAxiosError } from '@/shared/@types/error';
import { 
  SettlementsCalendarParams,
  SettlementsCalendarResponse
} from '../model/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';

export const settlementsCalendar = (params: SettlementsCalendarParams) => {
  return resultify(
    axios.post<SettlementsCalendarResponse>(API_URL_SETTLEMENT.settlementsCalendar(), params),
  );
};

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

  return {
    ...mutation,
  };
};
