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

export const SET_COLLECT_PROTOCOL_FEES_AUTHORITY_DISCRIMINATOR = new Uint8Array([34, 150, 93, 244, 139, 225, 233, 67]);

export function getSetCollectProtocolFeesAuthorityDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(SET_COLLECT_PROTOCOL_FEES_AUTHORITY_DISCRIMINATOR); }

export type SetCollectProtocolFeesAuthorityInstruction<TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, TAccountWhirlpoolsConfig extends string | AccountMeta<string> = string, TAccountCollectProtocolFeesAuthority extends string | AccountMeta<string> = string, TAccountNewCollectProtocolFeesAuthority extends string | AccountMeta<string> = string, TRemainingAccounts extends readonly AccountMeta<string>[] = []> =
Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array> & InstructionWithAccounts<[TAccountWhirlpoolsConfig extends string ? WritableAccount<TAccountWhirlpoolsConfig> : TAccountWhirlpoolsConfig, TAccountCollectProtocolFeesAuthority extends string ? ReadonlySignerAccount<TAccountCollectProtocolFeesAuthority> & AccountSignerMeta<TAccountCollectProtocolFeesAuthority> : TAccountCollectProtocolFeesAuthority, TAccountNewCollectProtocolFeesAuthority extends string ? ReadonlyAccount<TAccountNewCollectProtocolFeesAuthority> : TAccountNewCollectProtocolFeesAuthority, ...TRemainingAccounts]>;

export type SetCollectProtocolFeesAuthorityInstructionData = { discriminator: ReadonlyUint8Array;  };

export type SetCollectProtocolFeesAuthorityInstructionDataArgs = {  };

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

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

export function getSetCollectProtocolFeesAuthorityInstructionDataCodec(): FixedSizeCodec<SetCollectProtocolFeesAuthorityInstructionDataArgs, SetCollectProtocolFeesAuthorityInstructionData> {
    return combineCodec(getSetCollectProtocolFeesAuthorityInstructionDataEncoder(), getSetCollectProtocolFeesAuthorityInstructionDataDecoder());
}

export type SetCollectProtocolFeesAuthorityInput<TAccountWhirlpoolsConfig extends string = string, TAccountCollectProtocolFeesAuthority extends string = string, TAccountNewCollectProtocolFeesAuthority extends string = string> =  {
  whirlpoolsConfig: Address<TAccountWhirlpoolsConfig>;
collectProtocolFeesAuthority: TransactionSigner<TAccountCollectProtocolFeesAuthority>;
newCollectProtocolFeesAuthority: Address<TAccountNewCollectProtocolFeesAuthority>;
}

export function getSetCollectProtocolFeesAuthorityInstruction<TAccountWhirlpoolsConfig extends string, TAccountCollectProtocolFeesAuthority extends string, TAccountNewCollectProtocolFeesAuthority extends string, TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS>(input: SetCollectProtocolFeesAuthorityInput<TAccountWhirlpoolsConfig, TAccountCollectProtocolFeesAuthority, TAccountNewCollectProtocolFeesAuthority>, config?: { programAddress?: TProgramAddress } ): SetCollectProtocolFeesAuthorityInstruction<TProgramAddress, TAccountWhirlpoolsConfig, TAccountCollectProtocolFeesAuthority, TAccountNewCollectProtocolFeesAuthority> {
  // Program address.
const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS;

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




const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
return Object.freeze({ accounts: [getAccountMeta(accounts.whirlpoolsConfig), getAccountMeta(accounts.collectProtocolFeesAuthority), getAccountMeta(accounts.newCollectProtocolFeesAuthority)], data: getSetCollectProtocolFeesAuthorityInstructionDataEncoder().encode({}), programAddress } as SetCollectProtocolFeesAuthorityInstruction<TProgramAddress, TAccountWhirlpoolsConfig, TAccountCollectProtocolFeesAuthority, TAccountNewCollectProtocolFeesAuthority>);
}

export type ParsedSetCollectProtocolFeesAuthorityInstruction<TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[]> = { programAddress: Address<TProgram>;
accounts: {
whirlpoolsConfig: TAccountMetas[0];
collectProtocolFeesAuthority: TAccountMetas[1];
newCollectProtocolFeesAuthority: TAccountMetas[2];
};
data: SetCollectProtocolFeesAuthorityInstructionData; };

export function parseSetCollectProtocolFeesAuthorityInstruction<TProgram extends string, TAccountMetas extends readonly AccountMeta[]>(instruction: Instruction<TProgram> & InstructionWithAccounts<TAccountMetas> & InstructionWithData<ReadonlyUint8Array>): ParsedSetCollectProtocolFeesAuthorityInstruction<TProgram, TAccountMetas> {
  if (instruction.accounts.length < 3) {
  // 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: { whirlpoolsConfig: getNextAccount(), collectProtocolFeesAuthority: getNextAccount(), newCollectProtocolFeesAuthority: getNextAccount() }, data: getSetCollectProtocolFeesAuthorityInstructionDataDecoder().decode(instruction.data) };
}