/**
 * 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 {
  isProgramError,
  type Address,
  type SOLANA_ERROR__INSTRUCTION_ERROR__CUSTOM,
  type SolanaError,
} from "@solana/kit";
import { PRIVATE_CHANNEL_WITHDRAW_PROGRAM_PROGRAM_ADDRESS } from "../programs";

export const PRIVATE_CHANNEL_WITHDRAW_PROGRAM_ERROR__INVALID_MINT = 0x0; // 0
export const PRIVATE_CHANNEL_WITHDRAW_PROGRAM_ERROR__ZERO_AMOUNT = 0x1; // 1

export type PrivateChannelWithdrawProgramError =
  | typeof PRIVATE_CHANNEL_WITHDRAW_PROGRAM_ERROR__INVALID_MINT
  | typeof PRIVATE_CHANNEL_WITHDRAW_PROGRAM_ERROR__ZERO_AMOUNT;

let privateChannelWithdrawProgramErrorMessages:
  | Record<PrivateChannelWithdrawProgramError, string>
  | undefined;
if (process.env["NODE_ENV"] !== "production") {
  privateChannelWithdrawProgramErrorMessages = {
    [PRIVATE_CHANNEL_WITHDRAW_PROGRAM_ERROR__INVALID_MINT]: `Invalid mint provided`,
    [PRIVATE_CHANNEL_WITHDRAW_PROGRAM_ERROR__ZERO_AMOUNT]: `Withdrawal amount must be greater than zero`,
  };
}

export function getPrivateChannelWithdrawProgramErrorMessage(
  code: PrivateChannelWithdrawProgramError,
): string {
  if (process.env["NODE_ENV"] !== "production") {
    return (
      privateChannelWithdrawProgramErrorMessages as Record<
        PrivateChannelWithdrawProgramError,
        string
      >
    )[code];
  }

  return "Error message not available in production bundles.";
}

export function isPrivateChannelWithdrawProgramError<
  TProgramErrorCode extends PrivateChannelWithdrawProgramError,
>(
  error: unknown,
  transactionMessage: {
    instructions: Record<number, { programAddress: Address }>;
  },
  code?: TProgramErrorCode,
): error is SolanaError<typeof SOLANA_ERROR__INSTRUCTION_ERROR__CUSTOM> &
  Readonly<{ context: Readonly<{ code: TProgramErrorCode }> }> {
  return isProgramError<TProgramErrorCode>(
    error,
    transactionMessage,
    PRIVATE_CHANNEL_WITHDRAW_PROGRAM_PROGRAM_ADDRESS,
    code,
  );
}
