"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Travily = void 0;
const ApiHandler_1 = require("../helper/ApiHandler");
class Travily {
    constructor() {
        this.apiKey = process.env.TAVILY_API_KEY || "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";
        if (!this.apiKey) {
            throw new Error("TAVILY_API_KEY is not set in the environment variables.");
        }
        this.apiHandler = new ApiHandler_1.ApiHandler("https://api.tavily.com/search");
    }
    async search(query) {
        try {
            const data = {
                query: query.query,
                topic: query.topic,
                include_answer: query.include_answer,
                max_results: query.max_results,
                time_range: query.time_range,
                days: query.days,
                search_depth: query.search_depth,
            };
            return await this.apiHandler.post("", data, {
                "Authorization": `Bearer ${this.apiKey}`,
                "Content-Type": "application/json",
            }, data);
        }
        catch (error) {
            console.error("Error performing Tavily search:", error);
            return null;
        }
    }
}
exports.Travily = Travily;
