getMessage() . "\n"); } echo "Starting Gemini Market Advisor Engine...\n"; // 1. إنشاء جدول الإحصائيات الذكية إذا لم يكن موجوداً $sqlInit = " CREATE TABLE IF NOT EXISTS `gemini_market_insights` ( `id` INT AUTO_INCREMENT PRIMARY KEY, `insight_html` TEXT NOT NULL, `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; "; $con->exec($sqlInit); // 2. سحب آخر المعادلات المكتشفة $stmt = $con->query("SELECT * FROM competitor_secret_formulas"); $formulas = $stmt->fetchAll(PDO::FETCH_ASSOC); if (empty($formulas)) { echo "No formulas found to analyze. Run ai_formula_solver.php first.\n"; exit; } // 3. تمرير البيانات إلى Gemini $geminiService = new SiroGeminiService(); echo "Sending data to Gemini AI for strategic analysis...\n"; $result = $geminiService->analyzeCompetitorFormulas($formulas); if ($result && $result['status'] === 'success') { $htmlReport = $result['html_report']; // 4. حفظ التقرير في قاعدة البيانات $stmtInsert = $con->prepare("INSERT INTO gemini_market_insights (insight_html) VALUES (:html)"); $stmtInsert->execute([':html' => $htmlReport]); echo "Gemini analysis saved successfully! Admin can now view the strategic report.\n"; } else { echo "Failed to get analysis from Gemini. Check API keys and logs.\n"; } ?>