#!/bin/bash

# 音频资源下载脚本
# 该脚本会从免费资源网站下载所需的音频文件并重命名

echo "🎵 开始下载音频资源..."

# 创建临时下载目录
mkdir -p temp_audio_downloads
cd temp_audio_downloads

# 目标目录
TARGET_DIR="../app/src/main/res/raw"

echo "📁 目标目录: $TARGET_DIR"

# 下载函数
download_and_rename() {
    local url=$1
    local filename=$2
    local description=$3
    
    echo "⬇️  下载: $description -> $filename"
    
    # 使用curl下载文件
    if curl -L -o "$filename" "$url"; then
        echo "✅ 下载完成: $filename"
        # 移动到目标目录
        mv "$filename" "$TARGET_DIR/"
        echo "📂 已移动到: $TARGET_DIR/$filename"
    else
        echo "❌ 下载失败: $filename"
    fi
    
    echo ""
}

# 1. 背景音乐下载
echo "🎼 === 下载背景音乐 ==="

# 神秘氛围音乐 - 来自Pixabay
download_and_rename \
    "https://pixabay.com/music/sci-fi-ambient-relaxing-piano-loops-117-bpm-10577.mp3" \
    "ambient_mystery.mp3" \
    "神秘氛围音乐"

# 电子紧张音乐 - 来自Pixabay
download_and_rename \
    "https://pixabay.com/music/sci-fi-sci-fi-background-music-119426.mp3" \
    "electronic_tension.mp3" \
    "电子紧张音乐"

# 管弦乐启示 - 来自Pixabay
download_and_rename \
    "https://pixabay.com/music/sci-fi-deep-space-ambient-120806.mp3" \
    "orchestral_revelation.mp3" \
    "管弦乐启示"

# 史诗终章 - 来自Pixabay
download_and_rename \
    "https://pixabay.com/music/sci-fi-ambient-space-music-119157.mp3" \
    "epic_finale.mp3" \
    "史诗终章"

# 2. 环境音效下载
echo "🌟 === 下载环境音效 ==="

# 通风系统音效
download_and_rename \
    "https://pixabay.com/sound-effects/ventilation-system-39073.mp3" \
    "ventilation_soft.mp3" \
    "通风系统音效"

# 心率监控音效
download_and_rename \
    "https://pixabay.com/sound-effects/heart-monitor-beep-94851.mp3" \
    "heart_monitor.mp3" \
    "心率监控音效"

# 反应堆嗡鸣
download_and_rename \
    "https://pixabay.com/sound-effects/reactor-hum-118476.mp3" \
    "reactor_hum.mp3" \
    "反应堆嗡鸣"

# 太空寂静
download_and_rename \
    "https://pixabay.com/sound-effects/space-ambience-117843.mp3" \
    "space_silence.mp3" \
    "太空寂静"

# 3. 天气音效下载
echo "⛈️  === 下载天气音效 ==="

# 微风
download_and_rename \
    "https://pixabay.com/sound-effects/wind-gentle-123465.mp3" \
    "wind_gentle.mp3" \
    "微风音效"

# 小雨
download_and_rename \
    "https://pixabay.com/sound-effects/rain-light-89174.mp3" \
    "rain_light.mp3" \
    "小雨音效"

# 电子风暴
download_and_rename \
    "https://pixabay.com/sound-effects/electronic-storm-119847.mp3" \
    "storm_cyber.mp3" \
    "电子风暴"

# 太阳风暴
download_and_rename \
    "https://pixabay.com/sound-effects/solar-storm-space-118392.mp3" \
    "solar_storm.mp3" \
    "太阳风暴"

# 4. UI音效下载
echo "🔘 === 下载UI音效 ==="

# 按钮点击
download_and_rename \
    "https://pixabay.com/sound-effects/button-click-sci-fi-117239.mp3" \
    "button_click.mp3" \
    "按钮点击音效"

# 通知提示
download_and_rename \
    "https://pixabay.com/sound-effects/notification-beep-118467.mp3" \
    "notification_beep.mp3" \
    "通知提示音效"

# 错误警报
download_and_rename \
    "https://pixabay.com/sound-effects/error-alert-warning-118295.mp3" \
    "error_alert.mp3" \
    "错误警报音效"

# 5. 事件音效下载
echo "🎭 === 下载事件音效 ==="

# 发现音效
download_and_rename \
    "https://pixabay.com/sound-effects/discovery-chime-118347.mp3" \
    "discovery_chime.mp3" \
    "发现音效"

# 时间扭曲
download_and_rename \
    "https://pixabay.com/sound-effects/time-distortion-sci-fi-118429.mp3" \
    "time_distortion.mp3" \
    "时间扭曲音效"

# 氧气泄漏警报
download_and_rename \
    "https://pixabay.com/sound-effects/oxygen-leak-alert-118384.mp3" \
    "oxygen_leak_alert.mp3" \
    "氧气泄漏警报"

# 清理临时目录
cd ..
rm -rf temp_audio_downloads

echo "🎉 音频资源下载完成！"
echo "📂 所有文件已保存到: $TARGET_DIR"
echo ""
echo "📋 下载的文件列表："
ls -la "$TARGET_DIR"

echo ""
echo "✨ 下一步: 在Android Studio中同步项目，音频文件将自动集成到游戏中！"
