/**
 * 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, getU16Decoder, getU16Encoder, transformEncoder, type AccountMeta, type AccountSignerMeta, type Address, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type ReadonlySignerAccount, type ReadonlyUint8Array, type TransactionSigner, type WritableAccount } from '@solana/kit';
import { LB_CLMM_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';

export const SET_PRE_ACTIVATION_SLOT_DURATION_DISCRIMINATOR = new Uint8Array([24, 213, 73, 145, 1, 149, 127, 37]);

export function getSetPreActivationSlotDurationDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(SET_PRE_ACTIVATION_SLOT_DURATION_DISCRIMINATOR); }

export type SetPreActivationSlotDurationInstruction<TProgram extends string = typeof LB_CLMM_PROGRAM_ADDRESS, TAccountLbPair extends string | AccountMeta<string> = string, TAccountCreator extends string | AccountMeta<string> = string, TRemainingAccounts extends readonly AccountMeta<string>[] = []> =
Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array> & InstructionWithAccounts<[TAccountLbPair extends string ? WritableAccount<TAccountLbPair> : TAccountLbPair, TAccountCreator extends string ? ReadonlySignerAccount<TAccountCreator> & AccountSignerMeta<TAccountCreator> : TAccountCreator, ...TRemainingAccounts]>;

export type SetPreActivationSlotDurationInstructionData = { discriminator: ReadonlyUint8Array; preActivationSlotDuration: number;  };

export type SetPreActivationSlotDurationInstructionDataArgs = { preActivationSlotDuration: number;  };

export function getSetPreActivationSlotDurationInstructionDataEncoder(): FixedSizeEncoder<SetPreActivationSlotDurationInstructionDataArgs> {
    return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['preActivationSlotDuration', getU16Encoder()]]), (value) => ({ ...value, discriminator: SET_PRE_ACTIVATION_SLOT_DURATION_DISCRIMINATOR }));
}

export function getSetPreActivationSlotDurationInstructionDataDecoder(): FixedSizeDecoder<SetPreActivationSlotDurationInstructionData> {
    return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['preActivationSlotDuration', getU16Decoder()]]);
}

export function getSetPreActivationSlotDurationInstructionDataCodec(): FixedSizeCodec<SetPreActivationSlotDurationInstructionDataArgs, SetPreActivationSlotDurationInstructionData> {
    return combineCodec(getSetPreActivationSlotDurationInstructionDataEncoder(), getSetPreActivationSlotDurationInstructionDataDecoder());
}

export type SetPreActivationSlotDurationInput<TAccountLbPair extends string = string, TAccountCreator extends string = string> =  {
  lbPair: Address<TAccountLbPair>;
creator: TransactionSigner<TAccountCreator>;
preActivationSlotDuration: SetPreActivationSlotDurationInstructionDataArgs["preActivationSlotDuration"];
}

export function getSetPreActivationSlotDurationInstruction<TAccountLbPair extends string, TAccountCreator extends string, TProgramAddress extends Address = typeof LB_CLMM_PROGRAM_ADDRESS>(input: SetPreActivationSlotDurationInput<TAccountLbPair, TAccountCreator>, config?: { programAddress?: TProgramAddress } ): SetPreActivationSlotDurationInstruction<TProgramAddress, TAccountLbPair, TAccountCreator> {
  // Program address.
const programAddress = config?.programAddress ?? LB_CLMM_PROGRAM_ADDRESS;

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


// Original args.
const args = { ...input,  };




const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
return Object.freeze({ accounts: [getAccountMeta(accounts.lbPair), getAccountMeta(accounts.creator)], data: getSetPreActivationSlotDurationInstructionDataEncoder().encode(args as SetPreActivationSlotDurationInstructionDataArgs), programAddress } as SetPreActivationSlotDurationInstruction<TProgramAddress, TAccountLbPair, TAccountCreator>);
}

export type ParsedSetPreActivationSlotDurationInstruction<TProgram extends string = typeof LB_CLMM_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[]> = { programAddress: Address<TProgram>;
accounts: {
lbPair: TAccountMetas[0];
creator: TAccountMetas[1];
};
data: SetPreActivationSlotDurationInstructionData; };

export function parseSetPreActivationSlotDurationInstruction<TProgram extends string, TAccountMetas extends readonly AccountMeta[]>(instruction: Instruction<TProgram> & InstructionWithAccounts<TAccountMetas> & InstructionWithData<ReadonlyUint8Array>): ParsedSetPreActivationSlotDurationInstruction<TProgram, TAccountMetas> {
  if (instruction.accounts.length < 2) {
  // 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: { lbPair: getNextAccount(), creator: getNextAccount() }, data: getSetPreActivationSlotDurationInstructionDataDecoder().decode(instruction.data) };
}