/**
 * 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 Address, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type ReadonlyUint8Array, type WritableAccount } from '@solana/kit';
import { AMM_V3_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';

export const UPDATE_REWARD_INFOS_DISCRIMINATOR = new Uint8Array([163, 172, 224, 52, 11, 154, 106, 223]);

export function getUpdateRewardInfosDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(UPDATE_REWARD_INFOS_DISCRIMINATOR); }

export type UpdateRewardInfosInstruction<TProgram extends string = typeof AMM_V3_PROGRAM_ADDRESS, TAccountPoolState extends string | AccountMeta<string> = string, TRemainingAccounts extends readonly AccountMeta<string>[] = []> =
Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array> & InstructionWithAccounts<[TAccountPoolState extends string ? WritableAccount<TAccountPoolState> : TAccountPoolState, ...TRemainingAccounts]>;

export type UpdateRewardInfosInstructionData = { discriminator: ReadonlyUint8Array;  };

export type UpdateRewardInfosInstructionDataArgs = {  };

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

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

export function getUpdateRewardInfosInstructionDataCodec(): FixedSizeCodec<UpdateRewardInfosInstructionDataArgs, UpdateRewardInfosInstructionData> {
    return combineCodec(getUpdateRewardInfosInstructionDataEncoder(), getUpdateRewardInfosInstructionDataDecoder());
}

export type UpdateRewardInfosInput<TAccountPoolState extends string = string> =  {
  poolState: Address<TAccountPoolState>;
}

export function getUpdateRewardInfosInstruction<TAccountPoolState extends string, TProgramAddress extends Address = typeof AMM_V3_PROGRAM_ADDRESS>(input: UpdateRewardInfosInput<TAccountPoolState>, config?: { programAddress?: TProgramAddress } ): UpdateRewardInfosInstruction<TProgramAddress, TAccountPoolState> {
  // Program address.
const programAddress = config?.programAddress ?? AMM_V3_PROGRAM_ADDRESS;

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




const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
return Object.freeze({ accounts: [getAccountMeta(accounts.poolState)], data: getUpdateRewardInfosInstructionDataEncoder().encode({}), programAddress } as UpdateRewardInfosInstruction<TProgramAddress, TAccountPoolState>);
}

export type ParsedUpdateRewardInfosInstruction<TProgram extends string = typeof AMM_V3_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[]> = { programAddress: Address<TProgram>;
accounts: {
poolState: TAccountMetas[0];
};
data: UpdateRewardInfosInstructionData; };

export function parseUpdateRewardInfosInstruction<TProgram extends string, TAccountMetas extends readonly AccountMeta[]>(instruction: Instruction<TProgram> & InstructionWithAccounts<TAccountMetas> & InstructionWithData<ReadonlyUint8Array>): ParsedUpdateRewardInfosInstruction<TProgram, TAccountMetas> {
  if (instruction.accounts.length < 1) {
  // 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: { poolState: getNextAccount() }, data: getUpdateRewardInfosInstructionDataDecoder().decode(instruction.data) };
}