/**
 * This code was AUTOGENERATED using the codama library.
 * Please DO NOT EDIT THIS FILE, instead use visitors
 * to add features, then rerun codama to update it.
 *
 * @see https://github.com/codama-idl/codama
 */

import {
  Context,
  TransactionBuilder,
  transactionBuilder,
} from '@metaplex-foundation/umi';
import {
  Serializer,
  mapSerializer,
  struct,
  u64,
} from '@metaplex-foundation/umi/serializers';
import {
  ResolvedAccount,
  ResolvedAccountsWithIndices,
  getAccountMetasAndSigners,
} from '../shared';

// Data.
export type Instruction5InstructionData = { myArgument: bigint };

export type Instruction5InstructionDataArgs = { myArgument?: number | bigint };

export function getInstruction5InstructionDataSerializer(): Serializer<
  Instruction5InstructionDataArgs,
  Instruction5InstructionData
> {
  return mapSerializer<
    Instruction5InstructionDataArgs,
    any,
    Instruction5InstructionData
  >(
    struct<Instruction5InstructionData>([['myArgument', u64()]], {
      description: 'Instruction5InstructionData',
    }),
    (value) => ({ ...value, myArgument: value.myArgument ?? 42 })
  ) as Serializer<Instruction5InstructionDataArgs, Instruction5InstructionData>;
}

// Args.
export type Instruction5InstructionArgs = Instruction5InstructionDataArgs;

// Instruction.
export function instruction5(
  context: Pick<Context, 'programs'>,
  input: Instruction5InstructionArgs
): TransactionBuilder {
  // Program ID.
  const programId = context.programs.getPublicKey(
    'dummy',
    'Dummy1111111111111111111111111111111111'
  );

  // Accounts.
  const resolvedAccounts = {} satisfies ResolvedAccountsWithIndices;

  // Arguments.
  const resolvedArgs: Instruction5InstructionArgs = { ...input };

  // Accounts in order.
  const orderedAccounts: ResolvedAccount[] = Object.values(
    resolvedAccounts as ResolvedAccountsWithIndices
  );

  // Keys and Signers.
  const [keys, signers] = getAccountMetasAndSigners(
    orderedAccounts,
    'programId',
    programId
  );

  // Data.
  const data = getInstruction5InstructionDataSerializer().serialize(
    resolvedArgs as Instruction5InstructionDataArgs
  );

  // Bytes Created On Chain.
  const bytesCreatedOnChain = 0;

  return transactionBuilder([
    { instruction: { keys, programId, data }, signers, bytesCreatedOnChain },
  ]);
}
