import { getTime } from '../../../../onchain';
import { HistoryAccess } from '../../shared';

import { forceHistoryId } from './forceHistoryId';
import { getNewHistoryId } from './getNewHistoryId';

export const forceAccessToHistory = ({
  historyId: providedHistoryId,
  forceNew,
}: {
  historyId?: string;
  forceNew?: boolean;
} = {}): HistoryAccess => {
  const historyId = forceNew ? getNewHistoryId() : providedHistoryId || forceHistoryId();
  const timestamp = getTime();

  return {
    historyId,
    timestamp,
  };
};
