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

import { constructMutexBlockUnlockClaimTake, constructMutexUnlockBlock } from '../claims';
import { unlockMethodName } from '../methods';
import { unlockFee } from '../settings';
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: unlockFee,
        authenticated: null,
      },
      contractArgs: [],
    },
    ops: notify
      ? ([constructMutexUnlockBlock(lockId, issuer), constructMutexBlockUnlockClaimTake(lockId)] as const)
      : [],
    fee: unlockFee + (notify ? 1000n : 800n),
  };
};
