import { createJupiterApiClient, SwapApi, type QuoteResponse } from '@jup-ag/api';

export type JupiterQuoteParams = {
  amount: bigint;
  tokenIn: string;
  tokenOut: string;
  swapMode: 'ExactIn' | 'ExactOut';
  slippageBps?: number;
};

export class JupiterQuoteProvider {
  public swapApi: SwapApi;

  constructor() {
    this.swapApi = createJupiterApiClient({ fetchApi: fetch });
  }

  public async getQuote(params: JupiterQuoteParams): Promise<{ quote: QuoteResponse }> {
    const quote = await this.swapApi.quoteGet({
      amount: Number(params.amount),
      inputMint: params.tokenIn,
      outputMint: params.tokenOut,
      swapMode: params.swapMode,
      slippageBps: params.slippageBps,
    });

    return { quote };
  }
}
