/**
 * 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 {
  ClusterFilter,
  Context,
  Program,
  PublicKey,
} from '@metaplex-foundation/umi';
import { getSystemErrorFromCode, getSystemErrorFromName } from '../errors';

export const SYSTEM_PROGRAM_ID =
  '11111111111111111111111111111111' as PublicKey<'11111111111111111111111111111111'>;

export function createSystemProgram(): Program {
  return {
    name: 'system',
    publicKey: SYSTEM_PROGRAM_ID,
    getErrorFromCode(code: number, cause?: Error) {
      return getSystemErrorFromCode(code, this, cause);
    },
    getErrorFromName(name: string, cause?: Error) {
      return getSystemErrorFromName(name, this, cause);
    },
    isOnCluster() {
      return true;
    },
  };
}

export function getSystemProgram<T extends Program = Program>(
  context: Pick<Context, 'programs'>,
  clusterFilter?: ClusterFilter
): T {
  return context.programs.get<T>('system', clusterFilter);
}

export function getSystemProgramId(
  context: Pick<Context, 'programs'>,
  clusterFilter?: ClusterFilter
): PublicKey {
  return context.programs.getPublicKey(
    'system',
    SYSTEM_PROGRAM_ID,
    clusterFilter
  );
}
