import axios from 'axios';
import { API_URL_TRANSACTION } from '@/shared/api/api-url-transaction';
import { resultify } from '@/shared/lib/resultify';
import { NiceAxiosError } from '@/shared/@types/error';
import { 
  CashReceiptManualIssueParams,
  CashReceiptManualIssueResponse
} from '../model/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';
import { getHeaderUserAgent } from '@/shared/constants/url';

export const cashReceiptManualIssue = (params: CashReceiptManualIssueParams) => {
  let headerOptions = {
    menuId: 32,
    apiType: 'INSERT'
  };
  let options = {
    headers: {
      'X-User-Agent': getHeaderUserAgent(headerOptions)
    }
  };
  return resultify(
    axios.post<CashReceiptManualIssueResponse>(API_URL_TRANSACTION.cashReceiptManualIssue(), params, options),
  );
};

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

  return {
    ...mutation,
  };
};
