"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Trending = void 0;
const dotenv_1 = __importDefault(require("dotenv"));
const ApiHandler_1 = require("../helper/ApiHandler");
dotenv_1.default.config();
class Trending {
    constructor() {
        this.CryptoPanicAPIKEY = process.env.CRYPTOPANIC_API_KEY || "52552078fc7d26492a25ca0a57f7ec39453e52f5";
        this.CryptoPanicAPIHandler = new ApiHandler_1.ApiHandler("https://cryptopanic.com/api/free/v1/posts");
        this.CoinGeckoAPIHandler = new ApiHandler_1.ApiHandler("https://api.coingecko.com/api/v3/search/trending");
    }
    async getTrendingNews(tokens) {
        const response = await this.CryptoPanicAPIHandler.get(`?auth_token=${this.CryptoPanicAPIKEY}&public=true&filter=hot&approved=true&currencies=${tokens}`);
        if (!response)
            return [];
        return response.results.slice(0, 5).map(result => {
            var _a;
            return ({
                title: result.title,
                published_at: result.published_at,
                source: result.source.title,
                url: result.url,
                affected_currency: ((_a = result.currencies) === null || _a === void 0 ? void 0 : _a.map((currency) => currency.title).join(", ")) || "N/A",
                votes: result.votes
            });
        });
    }
    async getTrendingCoins() {
        const response = await this.CoinGeckoAPIHandler.get("?locale=en");
        if (!response)
            return [];
        return response.coins.slice(0, 5).map(coin => ({
            name: coin.item.name,
            symbol: coin.item.symbol,
            price: coin.item.price_btc,
            market_cap: coin.item.market_cap_rank,
            score: coin.item.score
        }));
    }
}
exports.Trending = Trending;
