import axios from "axios";

const GRAPH_BASE_URL = process.env.GRAPH_BASE_URL;
const GRAPH_API_KEY = process.env.GRAPH_API_KEY;

class GraphService {
  /**
   * Get all active exchange rates from Graph
   */
  static async getRates() {
    const url = `${GRAPH_BASE_URL}/rate`;
    try {
      const response = await axios.get(url, {
        headers: {
          Authorization: `Bearer ${GRAPH_API_KEY}`,
          Accept: "application/json",
        },
      });
      return response.data;
    } catch (error) {
      console.error("❌ Graph getRates error:", error.response?.data || error.message);
      throw new Error(error.response?.data?.message || "Failed to fetch rates from Graph API");
    }
  }
}

export default GraphService;
