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

import { constructMutexBlockLockClaimTake, constructMutexLockBlock, constructMutexLockClaimStore } from '../claims';
import { lockMethodName } from '../methods';
import { lockFee } from '../settings';
import { LockedKey } from '../types';

export const constructLockCall = ({
  issuer,
  keys,
  lockId,
  timestamp,
  processId,
}: {
  issuer: ContractIssuer;
  lockId: string;
  timestamp: number;
  keys: LockedKey[];
  processId: string;
}) => {
  return {
    callInfo: {
      ref: constructContractRef(issuer, []),
      methodInfo: {
        methodName: lockMethodName,
        methodArgs: [],
      },
      contractInfo: {
        providedCweb: lockFee,
        authenticated: null,
      },
      contractArgs: [],
    },
    inThreadOps: [constructMutexLockBlock(lockId, issuer), constructMutexBlockLockClaimTake(lockId)] as const,
    outThreadOps: [
      constructMutexLockClaimStore({ fee: lockFee, keys, lockId, timestamp, processId, locked: false }),
    ] as const,
    fee: lockFee * 2n + 200n,
  };
};
