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

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

export const useCashReceiptPurposeUpdateMutation = (options?: UseMutationOptions<CashReceiptPurposeUpdateResponse, NiceAxiosError, CashReceiptPurposeUpdateParams>) => {
  const mutation = useMutation<CashReceiptPurposeUpdateResponse, NiceAxiosError, CashReceiptPurposeUpdateParams>({
    ...options,
    mutationFn: (params: CashReceiptPurposeUpdateParams) => cashReceiptPurposeUpdate(params),
  });

  return {
    ...mutation,
  };
};
