/**
 * 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,
  fixEncoderSize,
  getBytesEncoder,
  type Address,
  type ReadonlyUint8Array,
} from '@solana/kit';
import {
  type ParsedCreateGuardInstruction,
  type ParsedExecuteInstruction,
  type ParsedInitializeInstruction,
  type ParsedUpdateGuardInstruction,
} from '../instructions';

export const WEN_TRANSFER_GUARD_PROGRAM_ADDRESS =
  'LockdqYQ9X2kwtWB99ioSbxubAmEi8o9jqYwbXgrrRw' as Address<'LockdqYQ9X2kwtWB99ioSbxubAmEi8o9jqYwbXgrrRw'>;

export enum WenTransferGuardAccount {
  GuardV1,
}

export function identifyWenTransferGuardAccount(
  account: { data: ReadonlyUint8Array } | ReadonlyUint8Array
): WenTransferGuardAccount {
  const data = 'data' in account ? account.data : account;
  if (
    containsBytes(
      data,
      fixEncoderSize(getBytesEncoder(), 8).encode(
        new Uint8Array([185, 149, 156, 78, 245, 108, 172, 68])
      ),
      0
    )
  ) {
    return WenTransferGuardAccount.GuardV1;
  }
  throw new Error(
    'The provided account could not be identified as a wenTransferGuard account.'
  );
}

export enum WenTransferGuardInstruction {
  CreateGuard,
  Execute,
  Initialize,
  UpdateGuard,
}

export function identifyWenTransferGuardInstruction(
  instruction: { data: ReadonlyUint8Array } | ReadonlyUint8Array
): WenTransferGuardInstruction {
  const data = 'data' in instruction ? instruction.data : instruction;
  if (
    containsBytes(
      data,
      fixEncoderSize(getBytesEncoder(), 8).encode(
        new Uint8Array([251, 254, 17, 198, 219, 218, 154, 99])
      ),
      0
    )
  ) {
    return WenTransferGuardInstruction.CreateGuard;
  }
  if (
    containsBytes(
      data,
      fixEncoderSize(getBytesEncoder(), 8).encode(
        new Uint8Array([105, 37, 101, 197, 75, 251, 102, 26])
      ),
      0
    )
  ) {
    return WenTransferGuardInstruction.Execute;
  }
  if (
    containsBytes(
      data,
      fixEncoderSize(getBytesEncoder(), 8).encode(
        new Uint8Array([43, 34, 13, 49, 167, 88, 235, 235])
      ),
      0
    )
  ) {
    return WenTransferGuardInstruction.Initialize;
  }
  if (
    containsBytes(
      data,
      fixEncoderSize(getBytesEncoder(), 8).encode(
        new Uint8Array([51, 38, 175, 180, 25, 249, 39, 24])
      ),
      0
    )
  ) {
    return WenTransferGuardInstruction.UpdateGuard;
  }
  throw new Error(
    'The provided instruction could not be identified as a wenTransferGuard instruction.'
  );
}

export type ParsedWenTransferGuardInstruction<
  TProgram extends string = 'LockdqYQ9X2kwtWB99ioSbxubAmEi8o9jqYwbXgrrRw',
> =
  | ({
      instructionType: WenTransferGuardInstruction.CreateGuard;
    } & ParsedCreateGuardInstruction<TProgram>)
  | ({
      instructionType: WenTransferGuardInstruction.Execute;
    } & ParsedExecuteInstruction<TProgram>)
  | ({
      instructionType: WenTransferGuardInstruction.Initialize;
    } & ParsedInitializeInstruction<TProgram>)
  | ({
      instructionType: WenTransferGuardInstruction.UpdateGuard;
    } & ParsedUpdateGuardInstruction<TProgram>);
