"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GenerateCategorySignal = void 0;
const StrategyCatalog_js_1 = require("../../domain/services/StrategyCatalog.js");
const AppError_js_1 = require("../../shared/errors/AppError.js");
const random_js_1 = require("../../shared/utils/random.js");
class GenerateCategorySignal {
    platformRepository;
    constructor(platformRepository) {
        this.platformRepository = platformRepository;
    }
    async execute(category) {
        const [tokens, platformStrategies] = await Promise.all([
            this.platformRepository.listTokens(),
            this.platformRepository.listStrategies()
        ]);
        const usableTokens = tokens.filter((token) => token.id && token.symbol);
        if (usableTokens.length === 0) {
            throw new AppError_js_1.AppError("No platform tokens are available for signal generation.", "NO_TOKENS", true);
        }
        const token = (0, random_js_1.chooseOne)(usableTokens);
        const strategyPool = platformStrategies.filter((strategy) => strategy.category === category);
        const strategy = (0, random_js_1.chooseOne)(strategyPool.length > 0 ? strategyPool : (0, StrategyCatalog_js_1.categoryStrategies)(category));
        const livePrice = await this.platformRepository.getTokenPrice(token.id, token.networkId).catch(() => undefined);
        const basePrice = livePrice ?? token.priceUsd ?? (0, random_js_1.randomFloat)(0.5, 500, 4);
        const direction = (0, random_js_1.randomFloat)(4, 18, 2);
        const targetPrice = Number((basePrice * (1 + direction / 100)).toFixed(6));
        return {
            tokenName: token.name,
            symbol: token.symbol,
            network: token.networkName,
            contractAddress: token.contractAddress,
            category,
            strategyName: strategy.name,
            entryPrice: Number(basePrice.toFixed(6)),
            targetPrice,
            riskLevel: (0, random_js_1.chooseOne)(["Low", "Medium", "High"]),
            suggestedAmountUsd: (0, random_js_1.randomInt)(969, 9696),
            executionWindow: `${(0, random_js_1.randomInt)(15, 90)} minutes`
        };
    }
}
exports.GenerateCategorySignal = GenerateCategorySignal;
