/**
 * 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,
  getBytesDecoder,
  getBytesEncoder,
  getStructDecoder,
  getStructEncoder,
  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 DENYLISTED_ACCOUNT_DISCRIMINATOR = new Uint8Array([
  186, 58, 212, 239, 102, 131, 157, 146,
]);

export function getDenylistedAccountDiscriminatorBytes() {
  return fixEncoderSize(getBytesEncoder(), 8).encode(
    DENYLISTED_ACCOUNT_DISCRIMINATOR,
  );
}

export type DenylistedAccount = {
  discriminator: ReadonlyUint8Array;
  account: Address;
};

export type DenylistedAccountArgs = { account: Address };

/** Gets the encoder for {@link DenylistedAccountArgs} account data. */
export function getDenylistedAccountEncoder(): FixedSizeEncoder<DenylistedAccountArgs> {
  return transformEncoder(
    getStructEncoder([
      ["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
      ["account", getAddressEncoder()],
    ]),
    (value) => ({ ...value, discriminator: DENYLISTED_ACCOUNT_DISCRIMINATOR }),
  );
}

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

/** Gets the codec for {@link DenylistedAccount} account data. */
export function getDenylistedAccountCodec(): FixedSizeCodec<
  DenylistedAccountArgs,
  DenylistedAccount
> {
  return combineCodec(
    getDenylistedAccountEncoder(),
    getDenylistedAccountDecoder(),
  );
}

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

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

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

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

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

export function getDenylistedAccountSize(): number {
  return 40;
}
