import { constructContractRef, ContractIssuer } from '@coinweb/contract-kit';

import { constructMutexBlockUnlockClaimTake, constructMutexUnlockBlock } from '../claims';
import { unlockMethodName } from '../methods';
import { MutexUnlockArgs } from '../types';

export const constructUnlockCall = (issuer: ContractIssuer, ...[lockId, timestamp, notify]: MutexUnlockArgs) => {
  return {
    callInfo: {
      ref: constructContractRef(issuer, []),
      methodInfo: {
        methodName: unlockMethodName,
        methodArgs: [lockId, timestamp] satisfies MutexUnlockArgs,
      },
      contractInfo: {
        providedCweb: 1000n,
        authenticated: null,
      },
      contractArgs: [],
    },
    ops: notify
      ? ([constructMutexUnlockBlock(lockId, issuer), constructMutexBlockUnlockClaimTake(lockId)] as const)
      : [],
    fee: 1200n,
  };
};
