#!/bin/bash

# 示例股票数据初始化脚本

cd "$(dirname "$0")"

# 创建数据库连接
DB="stock.db"

# 检查数据库是否存在
if [ ! -f "$DB" ]; then
    echo "❌ 数据库不存在，请先运行程序"
    exit 1
fi

# 插入示例股票数据
echo "📥 初始化示例股票数据..."

sqlite3 "$DB" <<EOF
-- Apple
INSERT INTO stocks (symbol, name, current_price, change, change_percent, market_cap, pe_ratio, roe, debt_ratio, update_time)
VALUES ('AAPL', 'Apple Inc.', 178.52, 2.34, 1.33, '2.8T', 28.5, 145.6, 0.15, datetime('now'));

-- Microsoft
INSERT INTO stocks (symbol, name, current_price, change, change_percent, market_cap, pe_ratio, roe, debt_ratio, update_time)
VALUES ('MSFT', 'Microsoft Corporation', 378.91, -1.23, -0.32, '2.8T', 32.1, 35.2, 0.25, datetime('now'));

-- Google
INSERT INTO stocks (symbol, name, current_price, 141.28, 3.42, 2.48, '1.8T', 25.3, 28.9, 0.18, datetime('now'));

-- Amazon
INSERT INTO stocks (symbol, name, current_price, change, change_percent, market_cap, pe_ratio, roe, debt_ratio, update_time)
VALUES ('AMZN', 'Amazon.com Inc.', 178.23, 1.87, 1.06, '1.9T', 42.5, 10.5, 0.45, datetime('now'));

-- NVIDIA
INSERT INTO stocks (symbol, name, current_price, change, change_percent, market_cap, pe_ratio, roe, debt_ratio, update_time)
VALUES ('NVDA', 'NVIDIA Corporation', 875.42, 15.67, 1.82, '2.2T', 65.2, 76.8, 0.08, datetime('now'));

-- Tesla
INSERT INTO stocks (symbol, name, current_price, change, change_percent, market_cap, pe_ratio, roe, debt_ratio, update_time)
VALUES ('TSLA', 'Tesla Inc.', 248.56, -5.43, -2.14, '785B', 85.3, 12.4, 0.38, datetime('now'));

-- Meta
INSERT INTO stocks (symbol, name, current_price, change, change_percent, market_cap, pe_ratio, roe, debt_ratio, update_time)
VALUES ('META', 'Meta Platforms Inc.', 505.34, 8.91, 1.80, '1.3T', 29.5, 37.2, 0.22, datetime('now'));

-- JPMorgan
INSERT INTO stocks (symbol, name, current_price, change, change_percent, market_cap, pe_ratio, roe, debt_ratio, update_time)
VALUES ('JPM', 'JPMorgan Chase & Co.', 198.45, 2.15, 1.10, '556B', 10.8, 16.5, 0.12, datetime('now'));

-- Visa
INSERT INTO stocks (symbol, name, current_price, change, change_percent, market_cap, pe_ratio, roe, debt_ratio, update_time)
VALUES ('V', 'Visa Inc.', 275.67, -0.87, -0.31, '645B', 32.4, 42.1, 0.18, datetime('now'));

-- Johnson & Johnson
INSERT INTO stocks (symbol, name, current_price, change, change_percent, market_cap, pe_ratio, roe, debt_ratio, update_time)
VALUES ('JNJ', 'Johnson & Johnson', 156.89, 1.34, 0.86, '380B', 13.5, 22.3, 0.05, datetime('now'));
EOF

echo "✅ 示例股票数据初始化完成！"
echo ""
echo "📚 已添加的股票:"
echo "  - AAPL (Apple)"
echo "  - MSFT (Microsoft)"
echo "  - GOOGL (Google)"
echo "  - AMZN (Amazon)"
echo "  - NVDA (NVIDIA)"
echo "  - TSLA (Tesla)"
echo "  - META (Meta)"
echo "  - JPM (JPMorgan)"
echo "  - V (Visa)"
echo "  - JNJ (Johnson & Johnson)"
echo ""
echo "💡 提示: 运行程序后访问 http://localhost:8080 查看股票列表"
