import { Claim, constructClaim } from '@coinweb/contract-kit';

import { getContext, getTime } from '../../../../onchain';
import { toHex } from '../../../../shared';
import { createHistoryItemKey, HistoryItem, HistoryItemClaimBody } from '../../shared';

export const createHistoryClaim = ({
  uniqueId,
  historyId,
  historyItem,
  order,
}: {
  uniqueId: string;
  historyId: string;
  historyItem: HistoryItem;
  order: number;
}): Claim => {
  const txId = getContext().call.txid;

  return constructClaim(
    createHistoryItemKey(historyId, getTime(), uniqueId, order),
    { ...historyItem, txId } satisfies HistoryItemClaimBody,
    toHex(0)
  );
};
