"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GenerateStockSignal = void 0;
const AppError_js_1 = require("../../shared/errors/AppError.js");
const random_js_1 = require("../../shared/utils/random.js");
const STOCK_STRATEGIES = ["Value Play", "Momentum Swing", "Growth Pick", "Dividend Aristocrat", "Fundamental Quality"];
class GenerateStockSignal {
    marketData;
    constructor(marketData) {
        this.marketData = marketData;
    }
    async execute(country, international) {
        const quotes = await this.marketData.getStocks({ country, international });
        if (quotes.length === 0) {
            const message = international
                ? `No international stock quotes available for ${country}.`
                : `No stock quotes available for ${country}. Try a different country or International stocks.`;
            throw new AppError_js_1.AppError(message, "NO_STOCK_QUOTES", true);
        }
        // Treat the curated list order as a "good fundamentals" ranking; pick randomly from the top 5.
        const topQuotes = quotes.slice(0, Math.min(5, quotes.length));
        const stock = (0, random_js_1.chooseOne)(topQuotes);
        const side = (0, random_js_1.chooseOne)(["BUY", "SELL"]);
        const movePct = (0, random_js_1.randomFloat)(2, 8, 2);
        const targetPrice = side === "BUY"
            ? Number((stock.price * (1 + movePct / 100)).toFixed(2))
            : Number((stock.price * (1 - movePct / 100)).toFixed(2));
        const priceContext = stock.isSimulated
            ? `estimated reference price of ${stock.price.toFixed(2)} ${stock.currency} (live quote unavailable for this market)`
            : `${stock.price.toFixed(2)} ${stock.currency}`;
        return {
            tokenName: stock.name,
            symbol: stock.symbol,
            category: "Stocks",
            side,
            strategyName: (0, random_js_1.chooseOne)(STOCK_STRATEGIES),
            entryPrice: stock.price,
            targetPrice,
            riskLevel: (0, random_js_1.chooseOne)(["Low", "Medium", "High"]),
            suggestedAmountUsd: (0, random_js_1.randomInt)(1000, 10000),
            executionWindow: `${(0, random_js_1.randomInt)(1, 30)} days`,
            reasoning: `${side} idea for ${stock.name} (${stock.symbol})${stock.sector ? ` in ${stock.sector}` : ""}. Selected from ${international ? "international" : "local"} quality fundamentals list at ${priceContext}.`,
            confidenceScore: (0, random_js_1.randomFloat)(5, 8, 1),
            sector: stock.sector,
            exchange: stock.exchange,
            marketCap: stock.marketCap,
            currency: stock.currency,
            isSimulated: stock.isSimulated
        };
    }
}
exports.GenerateStockSignal = GenerateStockSignal;
