/**
 * 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 {
  containsBytes,
  getU32Encoder,
  type Address,
  type ReadonlyUint8Array,
} from '@solana/kit';
import {
  type ParsedInstruction1Instruction,
  type ParsedInstruction2Instruction,
  type ParsedInstruction3Instruction,
  type ParsedInstruction4Instruction,
  type ParsedInstruction5Instruction,
  type ParsedInstruction6Instruction,
  type ParsedInstruction7Instruction,
} from '../instructions';

export const DUMMY_PROGRAM_ADDRESS =
  'Dummy1111111111111111111111111111111111' as Address<'Dummy1111111111111111111111111111111111'>;

export enum DummyInstruction {
  Instruction1,
  Instruction2,
  Instruction3,
  Instruction4,
  Instruction5,
  Instruction6,
  Instruction7,
}

export function identifyDummyInstruction(
  instruction: { data: ReadonlyUint8Array } | ReadonlyUint8Array
): DummyInstruction {
  const data = 'data' in instruction ? instruction.data : instruction;
  if (containsBytes(data, getU32Encoder().encode(42), 0)) {
    return DummyInstruction.Instruction3;
  }
  throw new Error(
    'The provided instruction could not be identified as a dummy instruction.'
  );
}

export type ParsedDummyInstruction<
  TProgram extends string = 'Dummy1111111111111111111111111111111111',
> =
  | ({
      instructionType: DummyInstruction.Instruction1;
    } & ParsedInstruction1Instruction<TProgram>)
  | ({
      instructionType: DummyInstruction.Instruction2;
    } & ParsedInstruction2Instruction<TProgram>)
  | ({
      instructionType: DummyInstruction.Instruction3;
    } & ParsedInstruction3Instruction<TProgram>)
  | ({
      instructionType: DummyInstruction.Instruction4;
    } & ParsedInstruction4Instruction<TProgram>)
  | ({
      instructionType: DummyInstruction.Instruction5;
    } & ParsedInstruction5Instruction<TProgram>)
  | ({
      instructionType: DummyInstruction.Instruction6;
    } & ParsedInstruction6Instruction<TProgram>)
  | ({
      instructionType: DummyInstruction.Instruction7;
    } & ParsedInstruction7Instruction<TProgram>);
