import { constructStore } from '@coinweb/contract-kit';

import { getTime } from '../../../../onchain';
import { createHistoryAccessClaim } from '../claims';

import { forceHistoryId } from './forceHistoryId';

export const constructNewHistoryAccess = ({
  accessId,
  historyId: providedHistoryId,
}: {
  accessId: string;
  historyId?: string;
}) => {
  const timestamp = getTime();

  const historyId = providedHistoryId ?? forceHistoryId();

  return [
    constructStore(
      createHistoryAccessClaim({
        id: accessId,
        timestamp,
        historyId,
      })
    ),
  ];
};
