import { constructContinueTx, constructContractRef, Context } from '@coinweb/contract-kit';
import { getCallParameters, getContractIssuer } from 'lib/onchain';

import { constructMutexLockClaimRangeRead } from '../claims';

import { execLockMethodName } from './names';

export const mutexLock = (context: Context) => {
  const { availableCweb } = getCallParameters(context);
  const issuer = getContractIssuer(context);

  return [
    constructContinueTx(
      context,
      [],
      [
        {
          callInfo: {
            ref: constructContractRef(issuer, []),
            methodInfo: {
              methodName: execLockMethodName,
              methodArgs: [],
            },
            contractInfo: {
              providedCweb: availableCweb - 700n,
              authenticated: null,
            },
            contractArgs: [constructMutexLockClaimRangeRead(issuer)],
          },
        },
      ]
    ),
  ];
};
