import { constructClaim } from '@coinweb/contract-kit';
import { cwait, readOp, storeOp, TypedClaim } from 'cwait';

import { createWordKey, WordClaimBody } from '../offchain';

import { extraLogic2 } from './extraLogic2';

export const extraLogic = cwait(async (id: string, i: number) => {
  console.log('extraLogic START + ', i);
  const result = await readOp<TypedClaim<WordClaimBody>>(createWordKey(id));

  await storeOp(
    constructClaim(
      createWordKey(id),
      { word: result?.body.word.split('').reverse().join('') + '_extraLogic + ' + i },
      '0x0'
    )
  );

  console.log('extraLogic return extraLogic2 + ', i);
  return extraLogic2(id, i);
});
