/**
 * 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 {
  type Account,
  type Address,
  assertAccountExists,
  assertAccountsExist,
  type Codec,
  combineCodec,
  type Decoder,
  decodeAccount,
  type EncodedAccount,
  type Encoder,
  type FetchAccountConfig,
  type FetchAccountsConfig,
  fetchEncodedAccount,
  fetchEncodedAccounts,
  getStructDecoder,
  getStructEncoder,
  type MaybeAccount,
  type MaybeEncodedAccount,
} from '@solana/kit';
import { ExtraMetasSeeds, findExtraMetasPda } from '../pdas';

export type ExtraMetas = {};

export type ExtraMetasArgs = ExtraMetas;

export function getExtraMetasEncoder(): Encoder<ExtraMetasArgs> {
  return getStructEncoder([]);
}

export function getExtraMetasDecoder(): Decoder<ExtraMetas> {
  return getStructDecoder([]);
}

export function getExtraMetasCodec(): Codec<ExtraMetasArgs, ExtraMetas> {
  return combineCodec(getExtraMetasEncoder(), getExtraMetasDecoder());
}

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

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

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

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

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

export async function fetchExtraMetasFromSeeds(
  rpc: Parameters<typeof fetchEncodedAccount>[0],
  seeds: ExtraMetasSeeds,
  config: FetchAccountConfig & { programAddress?: Address } = {},
): Promise<Account<ExtraMetas>> {
  const maybeAccount = await fetchMaybeExtraMetasFromSeeds(rpc, seeds, config);
  assertAccountExists(maybeAccount);
  return maybeAccount;
}

export async function fetchMaybeExtraMetasFromSeeds(
  rpc: Parameters<typeof fetchEncodedAccount>[0],
  seeds: ExtraMetasSeeds,
  config: FetchAccountConfig & { programAddress?: Address } = {},
): Promise<MaybeAccount<ExtraMetas>> {
  const { programAddress, ...fetchConfig } = config;
  const [address] = await findExtraMetasPda(seeds, { programAddress });
  return await fetchMaybeExtraMetas(rpc, address, fetchConfig);
}
