/**
 * 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 RENT_CLAIM_DISCRIMINATOR = new Uint8Array([
  13, 5, 183, 82, 60, 122, 72, 11,
]);

export function getRentClaimDiscriminatorBytes() {
  return fixEncoderSize(getBytesEncoder(), 8).encode(RENT_CLAIM_DISCRIMINATOR);
}

export type RentClaim = { discriminator: ReadonlyUint8Array; amount: bigint };

export type RentClaimArgs = { amount: number | bigint };

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

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

/** Gets the codec for {@link RentClaim} account data. */
export function getRentClaimCodec(): FixedSizeCodec<RentClaimArgs, RentClaim> {
  return combineCodec(getRentClaimEncoder(), getRentClaimDecoder());
}

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

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

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

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

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

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