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

export const cashReceiptManualIssue = (params: CashReceiptManualIssueParams) => {
  return resultify(
    axios.post<CashReceiptManualIssueResponse>(API_URL.cashReceiptManualIssue(), params),
  );
};

export const useCashReceiptManualIssueMutation = (options?: UseMutationOptions<CashReceiptManualIssueResponse, CBDCAxiosError, CashReceiptManualIssueParams>) => {
  const mutation = useMutation<CashReceiptManualIssueResponse, CBDCAxiosError, CashReceiptManualIssueParams>({
    ...options,
    mutationFn: (params: CashReceiptManualIssueParams) => cashReceiptManualIssue(params),
  });

  return {
    ...mutation,
  };
};
