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

/** NotUpgradeAuthority: Only the upgrade authority can call this instruction */
export const SPONSORED_CCTP_SRC_PERIPHERY_ERROR__NOT_UPGRADE_AUTHORITY = 0x1770; // 6000
/** InvalidProgramData: Invalid program data account */
export const SPONSORED_CCTP_SRC_PERIPHERY_ERROR__INVALID_PROGRAM_DATA = 0x1771; // 6001
/** CannotSetCurrentTime: Cannot set time if not in test mode */
export const SPONSORED_CCTP_SRC_PERIPHERY_ERROR__CANNOT_SET_CURRENT_TIME = 0x1772; // 6002
/** InvalidBurnToken: Invalid burn_token key */
export const SPONSORED_CCTP_SRC_PERIPHERY_ERROR__INVALID_BURN_TOKEN = 0x1773; // 6003
/** AmountNotPositive: Amount must be greater than 0 */
export const SPONSORED_CCTP_SRC_PERIPHERY_ERROR__AMOUNT_NOT_POSITIVE = 0x1774; // 6004
/** QuoteDeadlineNotPassed: The quote deadline has not passed! */
export const SPONSORED_CCTP_SRC_PERIPHERY_ERROR__QUOTE_DEADLINE_NOT_PASSED = 0x1775; // 6005
/** SignerUnchanged: New signer unchanged */
export const SPONSORED_CCTP_SRC_PERIPHERY_ERROR__SIGNER_UNCHANGED = 0x1776; // 6006
/** DepositAmountBelowMinimum: Deposit amount below minimum */
export const SPONSORED_CCTP_SRC_PERIPHERY_ERROR__DEPOSIT_AMOUNT_BELOW_MINIMUM = 0x1777; // 6007
/** MissingRentClaimAccount: Missing rent claim account */
export const SPONSORED_CCTP_SRC_PERIPHERY_ERROR__MISSING_RENT_CLAIM_ACCOUNT = 0x1778; // 6008
/** RentClaimOverflow: Rent claim amount overflow */
export const SPONSORED_CCTP_SRC_PERIPHERY_ERROR__RENT_CLAIM_OVERFLOW = 0x1779; // 6009
/** InvalidRecipientKey: Invalid recipient key */
export const SPONSORED_CCTP_SRC_PERIPHERY_ERROR__INVALID_RECIPIENT_KEY = 0x177a; // 6010

export type SponsoredCctpSrcPeripheryError =
  | typeof SPONSORED_CCTP_SRC_PERIPHERY_ERROR__AMOUNT_NOT_POSITIVE
  | typeof SPONSORED_CCTP_SRC_PERIPHERY_ERROR__CANNOT_SET_CURRENT_TIME
  | typeof SPONSORED_CCTP_SRC_PERIPHERY_ERROR__DEPOSIT_AMOUNT_BELOW_MINIMUM
  | typeof SPONSORED_CCTP_SRC_PERIPHERY_ERROR__INVALID_BURN_TOKEN
  | typeof SPONSORED_CCTP_SRC_PERIPHERY_ERROR__INVALID_PROGRAM_DATA
  | typeof SPONSORED_CCTP_SRC_PERIPHERY_ERROR__INVALID_RECIPIENT_KEY
  | typeof SPONSORED_CCTP_SRC_PERIPHERY_ERROR__MISSING_RENT_CLAIM_ACCOUNT
  | typeof SPONSORED_CCTP_SRC_PERIPHERY_ERROR__NOT_UPGRADE_AUTHORITY
  | typeof SPONSORED_CCTP_SRC_PERIPHERY_ERROR__QUOTE_DEADLINE_NOT_PASSED
  | typeof SPONSORED_CCTP_SRC_PERIPHERY_ERROR__RENT_CLAIM_OVERFLOW
  | typeof SPONSORED_CCTP_SRC_PERIPHERY_ERROR__SIGNER_UNCHANGED;

let sponsoredCctpSrcPeripheryErrorMessages:
  | Record<SponsoredCctpSrcPeripheryError, string>
  | undefined;
if (process.env.NODE_ENV !== "production") {
  sponsoredCctpSrcPeripheryErrorMessages = {
    [SPONSORED_CCTP_SRC_PERIPHERY_ERROR__AMOUNT_NOT_POSITIVE]: `Amount must be greater than 0`,
    [SPONSORED_CCTP_SRC_PERIPHERY_ERROR__CANNOT_SET_CURRENT_TIME]: `Cannot set time if not in test mode`,
    [SPONSORED_CCTP_SRC_PERIPHERY_ERROR__DEPOSIT_AMOUNT_BELOW_MINIMUM]: `Deposit amount below minimum`,
    [SPONSORED_CCTP_SRC_PERIPHERY_ERROR__INVALID_BURN_TOKEN]: `Invalid burn_token key`,
    [SPONSORED_CCTP_SRC_PERIPHERY_ERROR__INVALID_PROGRAM_DATA]: `Invalid program data account`,
    [SPONSORED_CCTP_SRC_PERIPHERY_ERROR__INVALID_RECIPIENT_KEY]: `Invalid recipient key`,
    [SPONSORED_CCTP_SRC_PERIPHERY_ERROR__MISSING_RENT_CLAIM_ACCOUNT]: `Missing rent claim account`,
    [SPONSORED_CCTP_SRC_PERIPHERY_ERROR__NOT_UPGRADE_AUTHORITY]: `Only the upgrade authority can call this instruction`,
    [SPONSORED_CCTP_SRC_PERIPHERY_ERROR__QUOTE_DEADLINE_NOT_PASSED]: `The quote deadline has not passed!`,
    [SPONSORED_CCTP_SRC_PERIPHERY_ERROR__RENT_CLAIM_OVERFLOW]: `Rent claim amount overflow`,
    [SPONSORED_CCTP_SRC_PERIPHERY_ERROR__SIGNER_UNCHANGED]: `New signer unchanged`,
  };
}

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

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

export function isSponsoredCctpSrcPeripheryError<
  TProgramErrorCode extends SponsoredCctpSrcPeripheryError,
>(
  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,
    SPONSORED_CCTP_SRC_PERIPHERY_PROGRAM_ADDRESS,
    code,
  );
}
