"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RuleBasedAIProvider = void 0;
const FAQS = [
    {
        patterns: ["payment", "paid", "pay", "deposit", "transaction"],
        response: "For payment-related issues, please ensure your transaction has the required confirmations on-chain. You can check your subscription status with /status. If the funds left your wallet but the subscription is not active, share the transaction hash and we'll investigate."
    },
    {
        patterns: ["subscription", "plan", "premium", "unlock"],
        response: "Subscriptions are tied to your Telegram ID and the selected platform. If you just paid, allow a few minutes for blockchain confirmations. Use the subscription menu to check status or upgrade your plan."
    },
    {
        patterns: ["signal", "signals", "not receiving", "no signal"],
        response: "Make sure you have an active subscription and haven't reached your daily request limit. You can request a new signal from the main menu. If a specific category fails repeatedly, let us know which one."
    },
    {
        patterns: ["withdraw", "wallet", "address", "private key"],
        response: "We never ask for your private key or seed phrase. If you need help with wallet connections or withdrawals, describe the issue and include any relevant wallet addresses (never share secrets)."
    }
];
const ESCALATION_KEYWORDS = [
    "human",
    "agent",
    "support",
    "real person",
    "talk to someone",
    "speak to",
    "representative",
    "operator",
    "manager",
    "supervisor",
    "urgent",
    "emergency",
    "hacked",
    "stolen",
    "scam",
    "fraud"
];
class RuleBasedAIProvider {
    config;
    constructor(config) {
        this.config = config;
    }
    async analyzeMessage(message) {
        const normalized = message.toLowerCase();
        const shouldEscalate = ESCALATION_KEYWORDS.some((keyword) => normalized.includes(keyword));
        if (shouldEscalate) {
            return {
                confidence: 1,
                suggestedPriority: "HIGH",
                sentiment: "NEGATIVE",
                urgency: "HIGH",
                shouldEscalate: true
            };
        }
        const matchedFaq = FAQS.find((faq) => faq.patterns.some((pattern) => normalized.includes(pattern)));
        if (matchedFaq) {
            return {
                response: matchedFaq.response,
                confidence: 0.85,
                suggestedCategory: this.guessCategory(normalized),
                suggestedPriority: this.guessPriority(normalized),
                sentiment: this.guessSentiment(normalized),
                urgency: this.guessUrgency(normalized),
                shouldEscalate: false
            };
        }
        return {
            confidence: 0.3,
            suggestedCategory: this.guessCategory(normalized),
            suggestedPriority: this.guessPriority(normalized),
            sentiment: this.guessSentiment(normalized),
            urgency: this.guessUrgency(normalized),
            shouldEscalate: false
        };
    }
    async generateReply(message) {
        const normalized = message.toLowerCase();
        const matchedFaq = FAQS.find((faq) => faq.patterns.some((pattern) => normalized.includes(pattern)));
        return matchedFaq?.response;
    }
    guessCategory(message) {
        if (message.includes("payment") || message.includes("pay") || message.includes("deposit"))
            return "Payment";
        if (message.includes("subscription") || message.includes("plan") || message.includes("premium"))
            return "Subscription";
        if (message.includes("signal"))
            return "Signals";
        if (message.includes("wallet") || message.includes("withdraw"))
            return "Wallet";
        if (message.includes("bug") || message.includes("error") || message.includes("not working"))
            return "Technical";
        return "General";
    }
    guessPriority(message) {
        if (message.includes("urgent") || message.includes("emergency") || message.includes("hacked"))
            return "URGENT";
        if (message.includes("error") || message.includes("not working") || message.includes("failed"))
            return "HIGH";
        if (message.includes("question") || message.includes("how"))
            return "NORMAL";
        return "LOW";
    }
    guessSentiment(message) {
        if (message.includes("thank") || message.includes("good") || message.includes("great"))
            return "POSITIVE";
        if (message.includes("bad") || message.includes("angry") || message.includes("frustrated") || message.includes("not working"))
            return "NEGATIVE";
        return "NEUTRAL";
    }
    guessUrgency(message) {
        if (message.includes("urgent") || message.includes("emergency") || message.includes("hacked"))
            return "HIGH";
        if (message.includes("error") || message.includes("failed"))
            return "MEDIUM";
        return "LOW";
    }
}
exports.RuleBasedAIProvider = RuleBasedAIProvider;
