/**
 * 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 ReadonlyAccount, type ReadonlyUint8Array, type WritableAccount } from '@solana/kit';
import { WHIRLPOOL_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';

export const UPDATE_FEES_AND_REWARDS_DISCRIMINATOR = new Uint8Array([154, 230, 250, 13, 236, 209, 75, 223]);

export function getUpdateFeesAndRewardsDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(UPDATE_FEES_AND_REWARDS_DISCRIMINATOR); }

export type UpdateFeesAndRewardsInstruction<TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, TAccountWhirlpool extends string | AccountMeta<string> = string, TAccountPosition extends string | AccountMeta<string> = string, TAccountTickArrayLower extends string | AccountMeta<string> = string, TAccountTickArrayUpper extends string | AccountMeta<string> = string, TRemainingAccounts extends readonly AccountMeta<string>[] = []> =
Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array> & InstructionWithAccounts<[TAccountWhirlpool extends string ? WritableAccount<TAccountWhirlpool> : TAccountWhirlpool, TAccountPosition extends string ? WritableAccount<TAccountPosition> : TAccountPosition, TAccountTickArrayLower extends string ? ReadonlyAccount<TAccountTickArrayLower> : TAccountTickArrayLower, TAccountTickArrayUpper extends string ? ReadonlyAccount<TAccountTickArrayUpper> : TAccountTickArrayUpper, ...TRemainingAccounts]>;

export type UpdateFeesAndRewardsInstructionData = { discriminator: ReadonlyUint8Array;  };

export type UpdateFeesAndRewardsInstructionDataArgs = {  };

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

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

export function getUpdateFeesAndRewardsInstructionDataCodec(): FixedSizeCodec<UpdateFeesAndRewardsInstructionDataArgs, UpdateFeesAndRewardsInstructionData> {
    return combineCodec(getUpdateFeesAndRewardsInstructionDataEncoder(), getUpdateFeesAndRewardsInstructionDataDecoder());
}

export type UpdateFeesAndRewardsInput<TAccountWhirlpool extends string = string, TAccountPosition extends string = string, TAccountTickArrayLower extends string = string, TAccountTickArrayUpper extends string = string> =  {
  whirlpool: Address<TAccountWhirlpool>;
position: Address<TAccountPosition>;
tickArrayLower: Address<TAccountTickArrayLower>;
tickArrayUpper: Address<TAccountTickArrayUpper>;
}

export function getUpdateFeesAndRewardsInstruction<TAccountWhirlpool extends string, TAccountPosition extends string, TAccountTickArrayLower extends string, TAccountTickArrayUpper extends string, TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS>(input: UpdateFeesAndRewardsInput<TAccountWhirlpool, TAccountPosition, TAccountTickArrayLower, TAccountTickArrayUpper>, config?: { programAddress?: TProgramAddress } ): UpdateFeesAndRewardsInstruction<TProgramAddress, TAccountWhirlpool, TAccountPosition, TAccountTickArrayLower, TAccountTickArrayUpper> {
  // Program address.
const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS;

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




const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
return Object.freeze({ accounts: [getAccountMeta(accounts.whirlpool), getAccountMeta(accounts.position), getAccountMeta(accounts.tickArrayLower), getAccountMeta(accounts.tickArrayUpper)], data: getUpdateFeesAndRewardsInstructionDataEncoder().encode({}), programAddress } as UpdateFeesAndRewardsInstruction<TProgramAddress, TAccountWhirlpool, TAccountPosition, TAccountTickArrayLower, TAccountTickArrayUpper>);
}

export type ParsedUpdateFeesAndRewardsInstruction<TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[]> = { programAddress: Address<TProgram>;
accounts: {
whirlpool: TAccountMetas[0];
position: TAccountMetas[1];
tickArrayLower: TAccountMetas[2];
tickArrayUpper: TAccountMetas[3];
};
data: UpdateFeesAndRewardsInstructionData; };

export function parseUpdateFeesAndRewardsInstruction<TProgram extends string, TAccountMetas extends readonly AccountMeta[]>(instruction: Instruction<TProgram> & InstructionWithAccounts<TAccountMetas> & InstructionWithData<ReadonlyUint8Array>): ParsedUpdateFeesAndRewardsInstruction<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: { whirlpool: getNextAccount(), position: getNextAccount(), tickArrayLower: getNextAccount(), tickArrayUpper: getNextAccount() }, data: getUpdateFeesAndRewardsInstructionDataDecoder().decode(instruction.data) };
}