import axios from 'axios';
import { API_URL } from '@/shared/api/urls';
import { resultify } from '@/shared/lib/resultify';
import { CBDCAxiosError } from '@/shared/@types/error';
import { 
  SettlementListParams,
  SettlementListResponse
} from '../model/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';

export const settlementList = (params: SettlementListParams) => {
  return resultify(
    axios.post<SettlementListResponse>(API_URL.settlementList(), params),
  );
};

export const useSettlementListMutation = (options?: UseMutationOptions<SettlementListResponse, CBDCAxiosError, SettlementListParams>) => {
  const mutation = useMutation<SettlementListResponse, CBDCAxiosError, SettlementListParams>({
    ...options,
    mutationFn: (params: SettlementListParams) => settlementList(params),
  });

  return {
    ...mutation,
  };
};
