/**
 * 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,
  getBytesDecoder,
  getBytesEncoder,
  getStructDecoder,
  getStructEncoder,
  getU64Decoder,
  getU64Encoder,
  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";

export const TRANSFER_LIABILITY_DISCRIMINATOR = new Uint8Array([
  157, 137, 86, 109, 206, 241, 183, 79,
]);

export function getTransferLiabilityDiscriminatorBytes() {
  return fixEncoderSize(getBytesEncoder(), 8).encode(
    TRANSFER_LIABILITY_DISCRIMINATOR,
  );
}

export type TransferLiability = {
  discriminator: ReadonlyUint8Array;
  pendingToHubPool: bigint;
};

export type TransferLiabilityArgs = { pendingToHubPool: number | bigint };

/** Gets the encoder for {@link TransferLiabilityArgs} account data. */
export function getTransferLiabilityEncoder(): FixedSizeEncoder<TransferLiabilityArgs> {
  return transformEncoder(
    getStructEncoder([
      ["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
      ["pendingToHubPool", getU64Encoder()],
    ]),
    (value) => ({ ...value, discriminator: TRANSFER_LIABILITY_DISCRIMINATOR }),
  );
}

/** Gets the decoder for {@link TransferLiability} account data. */
export function getTransferLiabilityDecoder(): FixedSizeDecoder<TransferLiability> {
  return getStructDecoder([
    ["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
    ["pendingToHubPool", getU64Decoder()],
  ]);
}

/** Gets the codec for {@link TransferLiability} account data. */
export function getTransferLiabilityCodec(): FixedSizeCodec<
  TransferLiabilityArgs,
  TransferLiability
> {
  return combineCodec(
    getTransferLiabilityEncoder(),
    getTransferLiabilityDecoder(),
  );
}

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

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

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

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

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

export function getTransferLiabilitySize(): number {
  return 16;
}
