/**
 * 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 Address, containsBytes, getU8Encoder, type ReadonlyUint8Array } from '@solana/kit';
import {
  type ParsedBlockWalletInstruction,
  type ParsedInitInstruction,
  type ParsedSetupExtraMetasInstruction,
  type ParsedUnblockWalletInstruction,
} from '../instructions';

export const BLOCK_LIST_PROGRAM_ADDRESS = 'BLoCKLSG2qMQ9YxEyrrKKAQzthvW4Lu8Eyv74axF6mf' as Address<'BLoCKLSG2qMQ9YxEyrrKKAQzthvW4Lu8Eyv74axF6mf'>;

export enum BlockListAccount {
  Config,
  WalletBlock,
  ExtraMetas,
}

export function identifyBlockListAccount(account: { data: ReadonlyUint8Array } | ReadonlyUint8Array): BlockListAccount {
  const data = 'data' in account ? account.data : account;
  if (containsBytes(data, getU8Encoder().encode(0), 0)) {
    return BlockListAccount.Config;
  }
  if (containsBytes(data, getU8Encoder().encode(1), 0)) {
    return BlockListAccount.WalletBlock;
  }
  throw new Error('The provided account could not be identified as a blockList account.');
}

export enum BlockListInstruction {
  Init,
  BlockWallet,
  UnblockWallet,
  SetupExtraMetas,
}

export function identifyBlockListInstruction(instruction: { data: ReadonlyUint8Array } | ReadonlyUint8Array): BlockListInstruction {
  const data = 'data' in instruction ? instruction.data : instruction;
  if (containsBytes(data, getU8Encoder().encode(241), 0)) {
    return BlockListInstruction.Init;
  }
  if (containsBytes(data, getU8Encoder().encode(242), 0)) {
    return BlockListInstruction.BlockWallet;
  }
  if (containsBytes(data, getU8Encoder().encode(243), 0)) {
    return BlockListInstruction.UnblockWallet;
  }
  if (containsBytes(data, getU8Encoder().encode(106), 0)) {
    return BlockListInstruction.SetupExtraMetas;
  }
  throw new Error('The provided instruction could not be identified as a blockList instruction.');
}

export type ParsedBlockListInstruction<TProgram extends string = 'BLoCKLSG2qMQ9YxEyrrKKAQzthvW4Lu8Eyv74axF6mf'> =
  | ({
      instructionType: BlockListInstruction.Init;
    } & ParsedInitInstruction<TProgram>)
  | ({
      instructionType: BlockListInstruction.BlockWallet;
    } & ParsedBlockWalletInstruction<TProgram>)
  | ({
      instructionType: BlockListInstruction.UnblockWallet;
    } & ParsedUnblockWalletInstruction<TProgram>)
  | ({
      instructionType: BlockListInstruction.SetupExtraMetas;
    } & ParsedSetupExtraMetasInstruction<TProgram>);
