/**
 * 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';
import { type AddCarArgs, addCarArgsBeet } from '../types/AddCarArgs';

/**
 * @category Instructions
 * @category AddCar
 * @category generated
 */
export type AddCarInstructionArgs = {
  addCarArgs: AddCarArgs;
};
/**
 * @category Instructions
 * @category AddCar
 * @category generated
 */
export const AddCarStruct = new beet.FixableBeetArgsStruct<
  AddCarInstructionArgs & {
    instructionDiscriminator: number;
  }
>(
  [
    ['instructionDiscriminator', beet.u8],
    ['addCarArgs', addCarArgsBeet],
  ],
  'AddCarInstructionArgs',
);
/**
 * Accounts required by the _AddCar_ instruction
 *
 * @property [_writable_] carAccount The account that will represent the Car being created
 * @property [_writable_] payer Fee payer
 * @category Instructions
 * @category AddCar
 * @category generated
 */
export type AddCarInstructionAccounts = {
  carAccount: web3.PublicKey;
  payer: web3.PublicKey;
  systemProgram?: web3.PublicKey;
};

export const addCarInstructionDiscriminator = 0;

/**
 * Creates a _AddCar_ 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 AddCar
 * @category generated
 */
export function createAddCarInstruction(
  accounts: AddCarInstructionAccounts,
  args: AddCarInstructionArgs,
  programId = new web3.PublicKey('8avNGHVXDwsELJaWMSoUZ44CirQd4zyU9Ez4ZmP4jNjZ'),
) {
  const [data] = AddCarStruct.serialize({
    instructionDiscriminator: addCarInstructionDiscriminator,
    ...args,
  });
  const keys: web3.AccountMeta[] = [
    {
      pubkey: accounts.carAccount,
      isWritable: true,
      isSigner: false,
    },
    {
      pubkey: accounts.payer,
      isWritable: true,
      isSigner: false,
    },
    {
      pubkey: accounts.systemProgram ?? web3.SystemProgram.programId,
      isWritable: false,
      isSigner: false,
    },
  ];

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