/**
 * This code was GENERATED using the solita package.
 * Please DO NOT EDIT THIS FILE, instead rerun solita to update it or write a wrapper to add functionality.
 *
 * See: https://github.com/metaplex-foundation/solita
 */

import * as beet from "@metaplex-foundation/beet";
import * as web3 from "@solana/web3.js";

/**
 * @category Instructions
 * @category AddEntity
 * @category generated
 */
export interface AddEntityInstructionArgs {
  extraSeed: beet.COption<string>;
}
/**
 * @category Instructions
 * @category AddEntity
 * @category generated
 */
export const addEntityStruct = new beet.FixableBeetArgsStruct<
  AddEntityInstructionArgs & {
    instructionDiscriminator: number[] /* size: 8 */;
  }
>(
  [
    ["instructionDiscriminator", beet.uniformFixedSizeArray(beet.u8, 8)],
    ["extraSeed", beet.coption(beet.utf8String)],
  ],
  "AddEntityInstructionArgs"
);
/**
 * Accounts required by the _addEntity_ instruction
 *
 * @property [_writable_, **signer**] payer
 * @property [_writable_] entity
 * @property [_writable_] world
 * @category Instructions
 * @category AddEntity
 * @category generated
 */
export interface AddEntityInstructionAccounts {
  payer: web3.PublicKey;
  entity: web3.PublicKey;
  world: web3.PublicKey;
  systemProgram?: web3.PublicKey;
  anchorRemainingAccounts?: web3.AccountMeta[];
}

export const addEntityInstructionDiscriminator = [
  163, 241, 57, 35, 244, 244, 48, 57,
];

/**
 * Creates a _AddEntity_ instruction.
 *
 * @param accounts that will be accessed while the instruction is processed
 * @param args to provide as instruction data to the program
 *
 * @category Instructions
 * @category AddEntity
 * @category generated
 */
export function createAddEntityInstruction(
  accounts: AddEntityInstructionAccounts,
  args: AddEntityInstructionArgs = { extraSeed: null },
  programId = new web3.PublicKey("WorLD15A7CrDwLcLy4fRqtaTb9fbd8o8iqiEMUDse2n")
) {
  const [data] = addEntityStruct.serialize({
    instructionDiscriminator: addEntityInstructionDiscriminator,
    ...args,
  });
  const keys: web3.AccountMeta[] = [
    {
      pubkey: accounts.payer,
      isWritable: true,
      isSigner: true,
    },
    {
      pubkey: accounts.entity,
      isWritable: true,
      isSigner: false,
    },
    {
      pubkey: accounts.world,
      isWritable: true,
      isSigner: false,
    },
    {
      pubkey: accounts.systemProgram ?? web3.SystemProgram.programId,
      isWritable: false,
      isSigner: false,
    },
  ];

  if (accounts.anchorRemainingAccounts != null) {
    for (const acc of accounts.anchorRemainingAccounts) {
      keys.push(acc);
    }
  }

  const ix = new web3.TransactionInstruction({
    programId,
    keys,
    data,
  });
  return ix;
}
