/**
 * 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 {
  assertIsInstructionWithAccounts,
  containsBytes,
  fixEncoderSize,
  getBytesEncoder,
  type Address,
  type Instruction,
  type InstructionWithData,
  type ReadonlyUint8Array,
} from "@solana/kit";
import {
  parseDepositForBurnInstruction,
  parseGetUsedNonceCloseInfoInstruction,
  parseInitializeInstruction,
  parseReclaimEventAccountInstruction,
  parseReclaimUsedNonceAccountInstruction,
  parseRepayRentFundDebtInstruction,
  parseSetCurrentTimeInstruction,
  parseSetMinimumDepositAmountInstruction,
  parseSetSignerInstruction,
  parseWithdrawRentFundInstruction,
  type ParsedDepositForBurnInstruction,
  type ParsedGetUsedNonceCloseInfoInstruction,
  type ParsedInitializeInstruction,
  type ParsedReclaimEventAccountInstruction,
  type ParsedReclaimUsedNonceAccountInstruction,
  type ParsedRepayRentFundDebtInstruction,
  type ParsedSetCurrentTimeInstruction,
  type ParsedSetMinimumDepositAmountInstruction,
  type ParsedSetSignerInstruction,
  type ParsedWithdrawRentFundInstruction,
} from "../instructions";

export const SPONSORED_CCTP_SRC_PERIPHERY_PROGRAM_ADDRESS =
  "FsD4uqAyXiAcQapVTokNvdz1ZC5hMHjY6a93nYmEqZQS" as Address<"FsD4uqAyXiAcQapVTokNvdz1ZC5hMHjY6a93nYmEqZQS">;

export enum SponsoredCctpSrcPeripheryAccount {
  MessageSent,
  MinimumDeposit,
  RentClaim,
  State,
  UsedNonce,
}

export function identifySponsoredCctpSrcPeripheryAccount(
  account: { data: ReadonlyUint8Array } | ReadonlyUint8Array,
): SponsoredCctpSrcPeripheryAccount {
  const data = "data" in account ? account.data : account;
  if (
    containsBytes(
      data,
      fixEncoderSize(getBytesEncoder(), 8).encode(
        new Uint8Array([131, 100, 133, 56, 166, 225, 151, 60]),
      ),
      0,
    )
  ) {
    return SponsoredCctpSrcPeripheryAccount.MessageSent;
  }
  if (
    containsBytes(
      data,
      fixEncoderSize(getBytesEncoder(), 8).encode(
        new Uint8Array([218, 139, 120, 202, 3, 12, 233, 65]),
      ),
      0,
    )
  ) {
    return SponsoredCctpSrcPeripheryAccount.MinimumDeposit;
  }
  if (
    containsBytes(
      data,
      fixEncoderSize(getBytesEncoder(), 8).encode(
        new Uint8Array([13, 5, 183, 82, 60, 122, 72, 11]),
      ),
      0,
    )
  ) {
    return SponsoredCctpSrcPeripheryAccount.RentClaim;
  }
  if (
    containsBytes(
      data,
      fixEncoderSize(getBytesEncoder(), 8).encode(
        new Uint8Array([216, 146, 107, 94, 104, 75, 182, 177]),
      ),
      0,
    )
  ) {
    return SponsoredCctpSrcPeripheryAccount.State;
  }
  if (
    containsBytes(
      data,
      fixEncoderSize(getBytesEncoder(), 8).encode(
        new Uint8Array([212, 222, 157, 252, 130, 71, 179, 238]),
      ),
      0,
    )
  ) {
    return SponsoredCctpSrcPeripheryAccount.UsedNonce;
  }
  throw new Error(
    "The provided account could not be identified as a sponsoredCctpSrcPeriphery account.",
  );
}

export enum SponsoredCctpSrcPeripheryInstruction {
  DepositForBurn,
  GetUsedNonceCloseInfo,
  Initialize,
  ReclaimEventAccount,
  ReclaimUsedNonceAccount,
  RepayRentFundDebt,
  SetCurrentTime,
  SetMinimumDepositAmount,
  SetSigner,
  WithdrawRentFund,
}

export function identifySponsoredCctpSrcPeripheryInstruction(
  instruction: { data: ReadonlyUint8Array } | ReadonlyUint8Array,
): SponsoredCctpSrcPeripheryInstruction {
  const data = "data" in instruction ? instruction.data : instruction;
  if (
    containsBytes(
      data,
      fixEncoderSize(getBytesEncoder(), 8).encode(
        new Uint8Array([215, 60, 61, 46, 114, 55, 128, 176]),
      ),
      0,
    )
  ) {
    return SponsoredCctpSrcPeripheryInstruction.DepositForBurn;
  }
  if (
    containsBytes(
      data,
      fixEncoderSize(getBytesEncoder(), 8).encode(
        new Uint8Array([19, 183, 42, 151, 118, 234, 57, 92]),
      ),
      0,
    )
  ) {
    return SponsoredCctpSrcPeripheryInstruction.GetUsedNonceCloseInfo;
  }
  if (
    containsBytes(
      data,
      fixEncoderSize(getBytesEncoder(), 8).encode(
        new Uint8Array([175, 175, 109, 31, 13, 152, 155, 237]),
      ),
      0,
    )
  ) {
    return SponsoredCctpSrcPeripheryInstruction.Initialize;
  }
  if (
    containsBytes(
      data,
      fixEncoderSize(getBytesEncoder(), 8).encode(
        new Uint8Array([94, 198, 180, 159, 131, 236, 15, 174]),
      ),
      0,
    )
  ) {
    return SponsoredCctpSrcPeripheryInstruction.ReclaimEventAccount;
  }
  if (
    containsBytes(
      data,
      fixEncoderSize(getBytesEncoder(), 8).encode(
        new Uint8Array([153, 152, 111, 172, 156, 104, 116, 3]),
      ),
      0,
    )
  ) {
    return SponsoredCctpSrcPeripheryInstruction.ReclaimUsedNonceAccount;
  }
  if (
    containsBytes(
      data,
      fixEncoderSize(getBytesEncoder(), 8).encode(
        new Uint8Array([111, 95, 222, 174, 241, 41, 61, 78]),
      ),
      0,
    )
  ) {
    return SponsoredCctpSrcPeripheryInstruction.RepayRentFundDebt;
  }
  if (
    containsBytes(
      data,
      fixEncoderSize(getBytesEncoder(), 8).encode(
        new Uint8Array([69, 100, 169, 193, 125, 0, 150, 69]),
      ),
      0,
    )
  ) {
    return SponsoredCctpSrcPeripheryInstruction.SetCurrentTime;
  }
  if (
    containsBytes(
      data,
      fixEncoderSize(getBytesEncoder(), 8).encode(
        new Uint8Array([176, 4, 74, 229, 206, 148, 151, 138]),
      ),
      0,
    )
  ) {
    return SponsoredCctpSrcPeripheryInstruction.SetMinimumDepositAmount;
  }
  if (
    containsBytes(
      data,
      fixEncoderSize(getBytesEncoder(), 8).encode(
        new Uint8Array([127, 120, 252, 184, 97, 4, 88, 68]),
      ),
      0,
    )
  ) {
    return SponsoredCctpSrcPeripheryInstruction.SetSigner;
  }
  if (
    containsBytes(
      data,
      fixEncoderSize(getBytesEncoder(), 8).encode(
        new Uint8Array([153, 28, 108, 116, 132, 70, 161, 125]),
      ),
      0,
    )
  ) {
    return SponsoredCctpSrcPeripheryInstruction.WithdrawRentFund;
  }
  throw new Error(
    "The provided instruction could not be identified as a sponsoredCctpSrcPeriphery instruction.",
  );
}

export type ParsedSponsoredCctpSrcPeripheryInstruction<
  TProgram extends string = "FsD4uqAyXiAcQapVTokNvdz1ZC5hMHjY6a93nYmEqZQS",
> =
  | ({
      instructionType: SponsoredCctpSrcPeripheryInstruction.DepositForBurn;
    } & ParsedDepositForBurnInstruction<TProgram>)
  | ({
      instructionType: SponsoredCctpSrcPeripheryInstruction.GetUsedNonceCloseInfo;
    } & ParsedGetUsedNonceCloseInfoInstruction<TProgram>)
  | ({
      instructionType: SponsoredCctpSrcPeripheryInstruction.Initialize;
    } & ParsedInitializeInstruction<TProgram>)
  | ({
      instructionType: SponsoredCctpSrcPeripheryInstruction.ReclaimEventAccount;
    } & ParsedReclaimEventAccountInstruction<TProgram>)
  | ({
      instructionType: SponsoredCctpSrcPeripheryInstruction.ReclaimUsedNonceAccount;
    } & ParsedReclaimUsedNonceAccountInstruction<TProgram>)
  | ({
      instructionType: SponsoredCctpSrcPeripheryInstruction.RepayRentFundDebt;
    } & ParsedRepayRentFundDebtInstruction<TProgram>)
  | ({
      instructionType: SponsoredCctpSrcPeripheryInstruction.SetCurrentTime;
    } & ParsedSetCurrentTimeInstruction<TProgram>)
  | ({
      instructionType: SponsoredCctpSrcPeripheryInstruction.SetMinimumDepositAmount;
    } & ParsedSetMinimumDepositAmountInstruction<TProgram>)
  | ({
      instructionType: SponsoredCctpSrcPeripheryInstruction.SetSigner;
    } & ParsedSetSignerInstruction<TProgram>)
  | ({
      instructionType: SponsoredCctpSrcPeripheryInstruction.WithdrawRentFund;
    } & ParsedWithdrawRentFundInstruction<TProgram>);

export function parseSponsoredCctpSrcPeripheryInstruction<
  TProgram extends string,
>(
  instruction: Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array>,
): ParsedSponsoredCctpSrcPeripheryInstruction<TProgram> {
  const instructionType =
    identifySponsoredCctpSrcPeripheryInstruction(instruction);
  switch (instructionType) {
    case SponsoredCctpSrcPeripheryInstruction.DepositForBurn: {
      assertIsInstructionWithAccounts(instruction);
      return {
        instructionType: SponsoredCctpSrcPeripheryInstruction.DepositForBurn,
        ...parseDepositForBurnInstruction(instruction),
      };
    }
    case SponsoredCctpSrcPeripheryInstruction.GetUsedNonceCloseInfo: {
      assertIsInstructionWithAccounts(instruction);
      return {
        instructionType:
          SponsoredCctpSrcPeripheryInstruction.GetUsedNonceCloseInfo,
        ...parseGetUsedNonceCloseInfoInstruction(instruction),
      };
    }
    case SponsoredCctpSrcPeripheryInstruction.Initialize: {
      assertIsInstructionWithAccounts(instruction);
      return {
        instructionType: SponsoredCctpSrcPeripheryInstruction.Initialize,
        ...parseInitializeInstruction(instruction),
      };
    }
    case SponsoredCctpSrcPeripheryInstruction.ReclaimEventAccount: {
      assertIsInstructionWithAccounts(instruction);
      return {
        instructionType:
          SponsoredCctpSrcPeripheryInstruction.ReclaimEventAccount,
        ...parseReclaimEventAccountInstruction(instruction),
      };
    }
    case SponsoredCctpSrcPeripheryInstruction.ReclaimUsedNonceAccount: {
      assertIsInstructionWithAccounts(instruction);
      return {
        instructionType:
          SponsoredCctpSrcPeripheryInstruction.ReclaimUsedNonceAccount,
        ...parseReclaimUsedNonceAccountInstruction(instruction),
      };
    }
    case SponsoredCctpSrcPeripheryInstruction.RepayRentFundDebt: {
      assertIsInstructionWithAccounts(instruction);
      return {
        instructionType: SponsoredCctpSrcPeripheryInstruction.RepayRentFundDebt,
        ...parseRepayRentFundDebtInstruction(instruction),
      };
    }
    case SponsoredCctpSrcPeripheryInstruction.SetCurrentTime: {
      assertIsInstructionWithAccounts(instruction);
      return {
        instructionType: SponsoredCctpSrcPeripheryInstruction.SetCurrentTime,
        ...parseSetCurrentTimeInstruction(instruction),
      };
    }
    case SponsoredCctpSrcPeripheryInstruction.SetMinimumDepositAmount: {
      assertIsInstructionWithAccounts(instruction);
      return {
        instructionType:
          SponsoredCctpSrcPeripheryInstruction.SetMinimumDepositAmount,
        ...parseSetMinimumDepositAmountInstruction(instruction),
      };
    }
    case SponsoredCctpSrcPeripheryInstruction.SetSigner: {
      assertIsInstructionWithAccounts(instruction);
      return {
        instructionType: SponsoredCctpSrcPeripheryInstruction.SetSigner,
        ...parseSetSignerInstruction(instruction),
      };
    }
    case SponsoredCctpSrcPeripheryInstruction.WithdrawRentFund: {
      assertIsInstructionWithAccounts(instruction);
      return {
        instructionType: SponsoredCctpSrcPeripheryInstruction.WithdrawRentFund,
        ...parseWithdrawRentFundInstruction(instruction),
      };
    }
    default:
      throw new Error(
        `Unrecognized instruction type: ${instructionType as string}`,
      );
  }
}
