import { IdlEvents, IdlTypes } from "@coral-xyz/anchor";
import { ParsedInstruction, PublicKey } from "@solana/web3.js";
import { Jupiter } from "@src/contracts/idl/jupiter";

export type SwapEvent = IdlEvents<Jupiter>["SwapEvent"];
export type FeeEvent = IdlEvents<Jupiter>["FeeEvent"];
type RoutePlanStep = IdlTypes<Jupiter>["RoutePlanStep"];
export type RoutePlan = RoutePlanStep[];

export interface PartialInstruction {
  programId: PublicKey;
  data: string /** Expecting base58 */;
  accounts: PublicKey[];
}

// Subset of @solana/web3.js ParsedTransactionWithMeta to allow flexible upstream data
export interface TransactionWithMeta {
  blockTime: number;
  meta: {
    status: {
      Ok: unknown;
    };
    logMessages?: string[] | null;
    innerInstructions?:
      | {
          index: number;
          instructions: (ParsedInstruction | PartialInstruction)[];
        }[]
      | null;
  } | null;
  transaction: {
    signatures: string[];
    message: {
      accountKeys: { pubkey: PublicKey }[];
      instructions: (ParsedInstruction | PartialInstruction)[];
    };
  };
}
