/**
 * 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 { assertAccountExists, assertAccountsExist, combineCodec, decodeAccount, fetchEncodedAccount, fetchEncodedAccounts, fixDecoderSize, fixEncoderSize, getAddressDecoder, getAddressEncoder, getArrayDecoder, getArrayEncoder, getBytesDecoder, getBytesEncoder, getI32Decoder, getI32Encoder, getStructDecoder, getStructEncoder, getU128Decoder, getU128Encoder, getU64Decoder, getU64Encoder, getU8Decoder, getU8Encoder, transformEncoder, type Account, type Address, type EncodedAccount, type FetchAccountConfig, type FetchAccountsConfig, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type MaybeAccount, type MaybeEncodedAccount, type ReadonlyUint8Array } from '@solana/kit';
import { getPositionRewardInfoDecoder, getPositionRewardInfoEncoder, type PositionRewardInfo, type PositionRewardInfoArgs } from '../types';

export const PERSONAL_POSITION_STATE_DISCRIMINATOR = new Uint8Array([70, 111, 150, 126, 230, 15, 25, 117]);

export function getPersonalPositionStateDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(PERSONAL_POSITION_STATE_DISCRIMINATOR); }

export type PersonalPositionState = { discriminator: ReadonlyUint8Array; bump: number; nftMint: Address; poolId: Address; tickLowerIndex: number; tickUpperIndex: number; liquidity: bigint; feeGrowthInside0LastX64: bigint; feeGrowthInside1LastX64: bigint; tokenFeesOwed0: bigint; tokenFeesOwed1: bigint; rewardInfos: Array<PositionRewardInfo>; padding: Array<bigint>;  };

export type PersonalPositionStateArgs = { bump: number; nftMint: Address; poolId: Address; tickLowerIndex: number; tickUpperIndex: number; liquidity: number | bigint; feeGrowthInside0LastX64: number | bigint; feeGrowthInside1LastX64: number | bigint; tokenFeesOwed0: number | bigint; tokenFeesOwed1: number | bigint; rewardInfos: Array<PositionRewardInfoArgs>; padding: Array<number | bigint>;  };

/** Gets the encoder for {@link PersonalPositionStateArgs} account data. */
export function getPersonalPositionStateEncoder(): FixedSizeEncoder<PersonalPositionStateArgs> {
    return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['bump', getU8Encoder()], ['nftMint', getAddressEncoder()], ['poolId', getAddressEncoder()], ['tickLowerIndex', getI32Encoder()], ['tickUpperIndex', getI32Encoder()], ['liquidity', getU128Encoder()], ['feeGrowthInside0LastX64', getU128Encoder()], ['feeGrowthInside1LastX64', getU128Encoder()], ['tokenFeesOwed0', getU64Encoder()], ['tokenFeesOwed1', getU64Encoder()], ['rewardInfos', getArrayEncoder(getPositionRewardInfoEncoder(), { size: 3 })], ['padding', getArrayEncoder(getU64Encoder(), { size: 8 })]]), (value) => ({ ...value, discriminator: PERSONAL_POSITION_STATE_DISCRIMINATOR }));
}

/** Gets the decoder for {@link PersonalPositionState} account data. */
export function getPersonalPositionStateDecoder(): FixedSizeDecoder<PersonalPositionState> {
    return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['bump', getU8Decoder()], ['nftMint', getAddressDecoder()], ['poolId', getAddressDecoder()], ['tickLowerIndex', getI32Decoder()], ['tickUpperIndex', getI32Decoder()], ['liquidity', getU128Decoder()], ['feeGrowthInside0LastX64', getU128Decoder()], ['feeGrowthInside1LastX64', getU128Decoder()], ['tokenFeesOwed0', getU64Decoder()], ['tokenFeesOwed1', getU64Decoder()], ['rewardInfos', getArrayDecoder(getPositionRewardInfoDecoder(), { size: 3 })], ['padding', getArrayDecoder(getU64Decoder(), { size: 8 })]]);
}

/** Gets the codec for {@link PersonalPositionState} account data. */
export function getPersonalPositionStateCodec(): FixedSizeCodec<PersonalPositionStateArgs, PersonalPositionState> {
    return combineCodec(getPersonalPositionStateEncoder(), getPersonalPositionStateDecoder());
}

export function decodePersonalPositionState<TAddress extends string = string>(encodedAccount: EncodedAccount<TAddress>): Account<PersonalPositionState, TAddress>;
export function decodePersonalPositionState<TAddress extends string = string>(encodedAccount: MaybeEncodedAccount<TAddress>): MaybeAccount<PersonalPositionState, TAddress>;
export function decodePersonalPositionState<TAddress extends string = string>(encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>): Account<PersonalPositionState, TAddress> | MaybeAccount<PersonalPositionState, TAddress> {
  return decodeAccount(encodedAccount as MaybeEncodedAccount<TAddress>, getPersonalPositionStateDecoder());
}

export async function fetchPersonalPositionState<TAddress extends string = string>(
  rpc: Parameters<typeof fetchEncodedAccount>[0],
  address: Address<TAddress>,
  config?: FetchAccountConfig,
): Promise<Account<PersonalPositionState, TAddress>> {
  const maybeAccount = await fetchMaybePersonalPositionState(rpc, address, config);
  assertAccountExists(maybeAccount);
  return maybeAccount;
}

export async function fetchMaybePersonalPositionState<TAddress extends string = string>(
  rpc: Parameters<typeof fetchEncodedAccount>[0],
  address: Address<TAddress>,
  config?: FetchAccountConfig,
): Promise<MaybeAccount<PersonalPositionState, TAddress>> {
  const maybeAccount = await fetchEncodedAccount(rpc, address, config);
  return decodePersonalPositionState(maybeAccount);
}

export async function fetchAllPersonalPositionState(
  rpc: Parameters<typeof fetchEncodedAccounts>[0],
  addresses: Array<Address>,
  config?: FetchAccountsConfig,
): Promise<Account<PersonalPositionState>[]> {
  const maybeAccounts = await fetchAllMaybePersonalPositionState(rpc, addresses, config);
  assertAccountsExist(maybeAccounts);
  return maybeAccounts;
}

export async function fetchAllMaybePersonalPositionState(
  rpc: Parameters<typeof fetchEncodedAccounts>[0],
  addresses: Array<Address>,
  config?: FetchAccountsConfig,
): Promise<MaybeAccount<PersonalPositionState>[]> {
  const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
  return maybeAccounts.map((maybeAccount) => decodePersonalPositionState(maybeAccount));
}

export function getPersonalPositionStateSize(): number {
  return 281;
}