/**
 * 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 { combineCodec, fixDecoderSize, fixEncoderSize, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, transformEncoder, type AccountMeta, type AccountSignerMeta, type Address, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type ReadonlyAccount, type ReadonlyUint8Array, type TransactionSigner, type WritableAccount, type WritableSignerAccount } from '@solana/kit';
import { YVAULTS_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';

export const RESIZE_TOKEN_INFOS_DISCRIMINATOR = new Uint8Array([29, 211, 127, 192, 213, 128, 200, 187]);

export function getResizeTokenInfosDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(RESIZE_TOKEN_INFOS_DISCRIMINATOR); }

export type ResizeTokenInfosInstruction<TProgram extends string = typeof YVAULTS_PROGRAM_ADDRESS, TAccountSigner extends string | AccountMeta<string> = string, TAccountTokenInfos extends string | AccountMeta<string> = string, TAccountSystemProgram extends string | AccountMeta<string> = "11111111111111111111111111111111", TAccountRent extends string | AccountMeta<string> = "SysvarRent111111111111111111111111111111111", TRemainingAccounts extends readonly AccountMeta<string>[] = []> =
Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array> & InstructionWithAccounts<[TAccountSigner extends string ? WritableSignerAccount<TAccountSigner> & AccountSignerMeta<TAccountSigner> : TAccountSigner, TAccountTokenInfos extends string ? WritableAccount<TAccountTokenInfos> : TAccountTokenInfos, TAccountSystemProgram extends string ? ReadonlyAccount<TAccountSystemProgram> : TAccountSystemProgram, TAccountRent extends string ? ReadonlyAccount<TAccountRent> : TAccountRent, ...TRemainingAccounts]>;

export type ResizeTokenInfosInstructionData = { discriminator: ReadonlyUint8Array;  };

export type ResizeTokenInfosInstructionDataArgs = {  };

export function getResizeTokenInfosInstructionDataEncoder(): FixedSizeEncoder<ResizeTokenInfosInstructionDataArgs> {
    return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: RESIZE_TOKEN_INFOS_DISCRIMINATOR }));
}

export function getResizeTokenInfosInstructionDataDecoder(): FixedSizeDecoder<ResizeTokenInfosInstructionData> {
    return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)]]);
}

export function getResizeTokenInfosInstructionDataCodec(): FixedSizeCodec<ResizeTokenInfosInstructionDataArgs, ResizeTokenInfosInstructionData> {
    return combineCodec(getResizeTokenInfosInstructionDataEncoder(), getResizeTokenInfosInstructionDataDecoder());
}

export type ResizeTokenInfosInput<TAccountSigner extends string = string, TAccountTokenInfos extends string = string, TAccountSystemProgram extends string = string, TAccountRent extends string = string> =  {
  signer: TransactionSigner<TAccountSigner>;
tokenInfos: Address<TAccountTokenInfos>;
systemProgram?: Address<TAccountSystemProgram>;
rent?: Address<TAccountRent>;
}

export function getResizeTokenInfosInstruction<TAccountSigner extends string, TAccountTokenInfos extends string, TAccountSystemProgram extends string, TAccountRent extends string, TProgramAddress extends Address = typeof YVAULTS_PROGRAM_ADDRESS>(input: ResizeTokenInfosInput<TAccountSigner, TAccountTokenInfos, TAccountSystemProgram, TAccountRent>, config?: { programAddress?: TProgramAddress } ): ResizeTokenInfosInstruction<TProgramAddress, TAccountSigner, TAccountTokenInfos, TAccountSystemProgram, TAccountRent> {
  // Program address.
const programAddress = config?.programAddress ?? YVAULTS_PROGRAM_ADDRESS;

 // Original accounts.
const originalAccounts = { signer: { value: input.signer ?? null, isWritable: true }, tokenInfos: { value: input.tokenInfos ?? null, isWritable: true }, systemProgram: { value: input.systemProgram ?? null, isWritable: false }, rent: { value: input.rent ?? null, isWritable: false } }
const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedAccount>;


// Resolve default values.
if (!accounts.systemProgram.value) {
accounts.systemProgram.value = '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>;
}
if (!accounts.rent.value) {
accounts.rent.value = 'SysvarRent111111111111111111111111111111111' as Address<'SysvarRent111111111111111111111111111111111'>;
}

const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
return Object.freeze({ accounts: [getAccountMeta(accounts.signer), getAccountMeta(accounts.tokenInfos), getAccountMeta(accounts.systemProgram), getAccountMeta(accounts.rent)], data: getResizeTokenInfosInstructionDataEncoder().encode({}), programAddress } as ResizeTokenInfosInstruction<TProgramAddress, TAccountSigner, TAccountTokenInfos, TAccountSystemProgram, TAccountRent>);
}

export type ParsedResizeTokenInfosInstruction<TProgram extends string = typeof YVAULTS_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[]> = { programAddress: Address<TProgram>;
accounts: {
signer: TAccountMetas[0];
tokenInfos: TAccountMetas[1];
systemProgram: TAccountMetas[2];
rent: TAccountMetas[3];
};
data: ResizeTokenInfosInstructionData; };

export function parseResizeTokenInfosInstruction<TProgram extends string, TAccountMetas extends readonly AccountMeta[]>(instruction: Instruction<TProgram> & InstructionWithAccounts<TAccountMetas> & InstructionWithData<ReadonlyUint8Array>): ParsedResizeTokenInfosInstruction<TProgram, TAccountMetas> {
  if (instruction.accounts.length < 4) {
  // TODO: Coded error.
  throw new Error('Not enough accounts');
}
let accountIndex = 0;
const getNextAccount = () => {
  const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
  accountIndex += 1;
  return accountMeta;
}
  return { programAddress: instruction.programAddress, accounts: { signer: getNextAccount(), tokenInfos: getNextAccount(), systemProgram: getNextAccount(), rent: getNextAccount() }, data: getResizeTokenInfosInstructionDataDecoder().decode(instruction.data) };
}