/**
 * 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 { TOKEN_MESSENGER_MINTER_V2_PROGRAM_ADDRESS } from "../programs";

/** InvalidAuthority: Invalid authority */
export const TOKEN_MESSENGER_MINTER_V2_ERROR__INVALID_AUTHORITY = 0x1770; // 6000
/** InvalidTokenMinterState: Invalid token minter state */
export const TOKEN_MESSENGER_MINTER_V2_ERROR__INVALID_TOKEN_MINTER_STATE = 0x1771; // 6001
/** ProgramPaused: Instruction is not allowed at this time */
export const TOKEN_MESSENGER_MINTER_V2_ERROR__PROGRAM_PAUSED = 0x1772; // 6002
/** InvalidTokenPairState: Invalid token pair state */
export const TOKEN_MESSENGER_MINTER_V2_ERROR__INVALID_TOKEN_PAIR_STATE = 0x1773; // 6003
/** InvalidLocalTokenState: Invalid local token state */
export const TOKEN_MESSENGER_MINTER_V2_ERROR__INVALID_LOCAL_TOKEN_STATE = 0x1774; // 6004
/** InvalidPauser: Invalid pauser */
export const TOKEN_MESSENGER_MINTER_V2_ERROR__INVALID_PAUSER = 0x1775; // 6005
/** InvalidTokenController: Invalid token controller */
export const TOKEN_MESSENGER_MINTER_V2_ERROR__INVALID_TOKEN_CONTROLLER = 0x1776; // 6006
/** BurnAmountExceeded: Burn amount exceeded */
export const TOKEN_MESSENGER_MINTER_V2_ERROR__BURN_AMOUNT_EXCEEDED = 0x1777; // 6007
/** InvalidAmount: Invalid amount */
export const TOKEN_MESSENGER_MINTER_V2_ERROR__INVALID_AMOUNT = 0x1778; // 6008

export type TokenMessengerMinterV2Error =
  | typeof TOKEN_MESSENGER_MINTER_V2_ERROR__BURN_AMOUNT_EXCEEDED
  | typeof TOKEN_MESSENGER_MINTER_V2_ERROR__INVALID_AMOUNT
  | typeof TOKEN_MESSENGER_MINTER_V2_ERROR__INVALID_AUTHORITY
  | typeof TOKEN_MESSENGER_MINTER_V2_ERROR__INVALID_LOCAL_TOKEN_STATE
  | typeof TOKEN_MESSENGER_MINTER_V2_ERROR__INVALID_PAUSER
  | typeof TOKEN_MESSENGER_MINTER_V2_ERROR__INVALID_TOKEN_CONTROLLER
  | typeof TOKEN_MESSENGER_MINTER_V2_ERROR__INVALID_TOKEN_MINTER_STATE
  | typeof TOKEN_MESSENGER_MINTER_V2_ERROR__INVALID_TOKEN_PAIR_STATE
  | typeof TOKEN_MESSENGER_MINTER_V2_ERROR__PROGRAM_PAUSED;

let tokenMessengerMinterV2ErrorMessages:
  | Record<TokenMessengerMinterV2Error, string>
  | undefined;
if (process.env.NODE_ENV !== "production") {
  tokenMessengerMinterV2ErrorMessages = {
    [TOKEN_MESSENGER_MINTER_V2_ERROR__BURN_AMOUNT_EXCEEDED]: `Burn amount exceeded`,
    [TOKEN_MESSENGER_MINTER_V2_ERROR__INVALID_AMOUNT]: `Invalid amount`,
    [TOKEN_MESSENGER_MINTER_V2_ERROR__INVALID_AUTHORITY]: `Invalid authority`,
    [TOKEN_MESSENGER_MINTER_V2_ERROR__INVALID_LOCAL_TOKEN_STATE]: `Invalid local token state`,
    [TOKEN_MESSENGER_MINTER_V2_ERROR__INVALID_PAUSER]: `Invalid pauser`,
    [TOKEN_MESSENGER_MINTER_V2_ERROR__INVALID_TOKEN_CONTROLLER]: `Invalid token controller`,
    [TOKEN_MESSENGER_MINTER_V2_ERROR__INVALID_TOKEN_MINTER_STATE]: `Invalid token minter state`,
    [TOKEN_MESSENGER_MINTER_V2_ERROR__INVALID_TOKEN_PAIR_STATE]: `Invalid token pair state`,
    [TOKEN_MESSENGER_MINTER_V2_ERROR__PROGRAM_PAUSED]: `Instruction is not allowed at this time`,
  };
}

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

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

export function isTokenMessengerMinterV2Error<
  TProgramErrorCode extends TokenMessengerMinterV2Error,
>(
  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,
    TOKEN_MESSENGER_MINTER_V2_PROGRAM_ADDRESS,
    code,
  );
}
