import { getMetadata, setSetMetadata } from './metadata';

export const updateMetadata = (newMetadata: { trackingId?: string; historyOrder?: number }) => {
  const currentMetadata = getMetadata();

  const trackingId = newMetadata.trackingId ?? currentMetadata?.trackingId;

  if (!trackingId) {
    return;
  }

  setSetMetadata({
    trackingId,
    historyOrder: newMetadata.historyOrder ?? currentMetadata?.historyOrder ?? null,
    historyLink: currentMetadata?.historyLink ?? null,
    accessId: currentMetadata?.accessId ?? null,
  });
};
