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) => {
  console.log('extraLogic START');
  const result = await readOp<TypedClaim<WordClaimBody>>(createWordKey(id));

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

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