#!/bin/bash

# ============================================
# COMPLETE Logo Downloader - All Categories
# Downloads ALL logos that need replacement
# ============================================

echo "🚀 Starting COMPLETE logo download..."
echo "⏰ This will take ~2-3 minutes..."
echo ""

LOGO_DIR="$HOME/complete-logos"
mkdir -p "$LOGO_DIR"
cd "$LOGO_DIR"

echo "📁 Saving to: $LOGO_DIR"
echo ""

SUCCESS=0
FAILED=0

download_logo() {
    local name=$1
    local domain=$2
    local filename=$3
    
    echo -n "⏳ $name... "
    
    # Try multiple sizes for better quality
    for size in 256 128 64; do
        if curl -s -L -o "$filename" "https://www.google.com/s2/favicons?domain=$domain&sz=$size" 2>/dev/null; then
            if [ -s "$filename" ] && [ $(stat -f%z "$filename" 2>/dev/null || stat -c%s "$filename") -gt 1000 ]; then
                echo "✅"
                ((SUCCESS++))
                return
            fi
        fi
    done
    
    echo "❌"
    ((FAILED++))
    rm -f "$filename" 2>/dev/null
}

# ============================================
# E-WALLETS
# ============================================
echo "💳 E-Wallets:"
download_logo "DANA" "dana.id" "dana.png"
download_logo "OVO" "ovo.id" "ovo.png"
download_logo "GoPay" "gojek.com" "gopay.png"
download_logo "LinkAja" "linkaja.id" "linkaja.png"
download_logo "ShopeePay" "shopee.co.id" "shopeepay.png"
download_logo "BRI Brizzi" "bri.co.id" "bri-brizzi.png"
download_logo "Mandiri E-Toll" "bankmandiri.co.id" "mandiri-e-toll.png"
echo ""

# ============================================
# TELCO / PULSA
# ============================================
echo "📱 Telco / Pulsa:"
download_logo "Telkomsel" "telkomsel.com" "telkomsel.png"
download_logo "Indosat" "indosat.com" "indosat.png"
download_logo "XL" "xl.co.id" "xl.png"
download_logo "Axis" "axis.co.id" "axis.png"
download_logo "Tri" "tri.co.id" "tri.png"
download_logo "Smartfren" "smartfren.com" "smartfren.png"
download_logo "BY.U" "byu.id" "byu.png"
echo ""

# ============================================
# PLN
# ============================================
echo "⚡ PLN:"
download_logo "PLN" "pln.co.id" "pln.png"
download_logo "PLN Promo" "pln.co.id" "pln-promo.png"
echo ""

# ============================================
# STREAMING
# ============================================
echo "📺 Streaming:"
download_logo "Netflix" "netflix.com" "netflix.png"
download_logo "Spotify" "spotify.com" "spotify.png"
download_logo "YouTube Premium" "youtube.com" "youtube-premium.png"
download_logo "Disney Plus" "disneyplus.com" "disney.png"
download_logo "Vidio" "vidio.com" "vidio.png"
download_logo "VIU" "viu.com" "viu.png"
download_logo "iQIYI Premium" "iqiyi.com" "iqiyi-premium.png"
download_logo "WeTV Premium" "wetv.vip" "wetv-premium.png"
download_logo "Amazon Prime Video" "primevideo.com" "amazon-prime-video.png"
download_logo "Bstation Premium" "bilibili.tv" "bstation-premium.png"
download_logo "K-VISION DAN GOL" "kvision.co.id" "k-vision-dan-gol.png"
echo ""

# ============================================
# SUBSCRIPTION APPS
# ============================================
echo "💎 Subscription Apps:"
download_logo "Canva Pro" "canva.com" "canva-pro.png"
download_logo "CapCut Pro" "capcut.com" "capcut-pro.png"
download_logo "Alight Motion" "alight.link" "alight-motion.png"
download_logo "ChatGPT" "openai.com" "chatgpt.png"
download_logo "Gemini" "gemini.google.com" "gemini.png"
download_logo "Perplexity AI" "perplexity.ai" "perplexity-ai.png"
download_logo "Notion" "notion.so" "notion.png"
download_logo "Grammarly" "grammarly.com" "grammarly.png"
download_logo "Warp Plus" "warp.plus" "warp-plus.png"
echo ""

# ============================================
# GAMES
# ============================================
echo "🎮 Games:"
download_logo "Mobile Legends" "mobilelegends.com" "mobile-legends.png"
download_logo "PUBG Mobile" "pubgmobile.com" "pubg.png"
download_logo "Free Fire" "ff.garena.com" "free-fire.png"
download_logo "Free Fire Max" "ff.garena.com" "free-fire-max.png"
download_logo "Genshin Impact" "genshin.hoyoverse.com" "genshin-impact.png"
download_logo "Honkai Impact 3" "honkaiimpact3.hoyoverse.com" "honkai-impact-3.png"
download_logo "Valorant" "playvalorant.com" "valorant.png"
download_logo "Lords Mobile" "lordsmobile.com" "lords-mobile.png"
download_logo "Arena of Valor" "arenaofvalor.com" "arena-of-valor.png"
download_logo "League of Legends" "leagueoflegends.com" "league-of-legends.png"
download_logo "Ace Racer" "aceracer.com" "ace-racer.png"
download_logo "Age of Empires Mobile" "ageofempires.com" "age-of-empires-mobile.png"
download_logo "Arena Breakout" "arenabreakout.com" "arena-breakout.png"
download_logo "Astral Guardians" "astralguardians.com" "astral-guardians.png"
download_logo "Be The King" "betheking.com" "be-the-king.png"
download_logo "Blood Strike" "bloodstrike.com" "blood-strike.png"
download_logo "Call of Duty" "callofduty.com" "call-of-duty.png"
download_logo "Conquer Online" "conqueronline.com" "conquer-online.png"
download_logo "Delta Force" "deltaforce.com" "delta-force.png"
download_logo "Dragon Raja" "dragonraja.com" "dragon-raja.png"
download_logo "Dragonheir Silent Gods" "dragonheir.com" "dragonheir-silent-gods.png"
download_logo "Dynasty Warriors" "dynastywarriors.com" "dynasty-warriors.png"
download_logo "EA SPORTS FC Mobile" "ea.com" "ea-sports-fc-mobile.png"
download_logo "Eggy Party" "eggyparty.com" "eggy-party.png"
download_logo "Farlight 84" "farlight84.com" "farlight-84.png"
download_logo "FIFA Master 2" "fifa.com" "fifa-master-2.png"
download_logo "Garena Undawn" "garena.com" "garena-undawn.png"
download_logo "King of Avalon" "kingofavalon.com" "king-of-avalon.png"
download_logo "Likee" "likee.video" "likee.png"
download_logo "LifeAfter" "lifeafter.game" "lifeafter.png"
download_logo "Light of Thel New Era" "lightofthel.com" "light-of-thel-new-era.png"
download_logo "Love and Deepspace" "loveanddeepspace.com" "love-and-deepspace.png"
download_logo "Magic Chess Go Go" "magiccgo.com" "magic-chess-go-go.png"
download_logo "Marvel Duel" "marvelduel.com" "marvel-duel.png"
download_logo "Marvel Rivals" "marvelrivals.com" "marvel-rivals.png"
download_logo "Identity V" "identityv.com" "identity-v.png"
download_logo "Infinite Borders" "infiniteborders.com" "infinite-borders.png"
echo ""

# ============================================
# VOUCHERS
# ============================================
echo "🎫 Vouchers:"
download_logo "Steam Wallet" "steampowered.com" "steam-wallet-code.png"
download_logo "Razer Gold" "razer.com" "razer-gold.png"
download_logo "Grab" "grab.com" "grab.png"
download_logo "Grab Driver" "grab.com" "grab-driver.png"
download_logo "GO PAY" "gojek.com" "go-pay.png"
download_logo "GO PAY DRIVER" "gojek.com" "go-pay-driver.png"
download_logo "Shopee" "shopee.co.id" "shopee.png"
download_logo "SHOPEE PAY" "shopee.co.id" "shopee-pay.png"
download_logo "Tokopedia" "tokopedia.com" "tokopedia.png"
download_logo "Alfamart" "alfamartku.com" "alfamart.png"
download_logo "ALFAMART VOUCHER" "alfamartku.com" "alfamart-voucher.png"
download_logo "Indomaret" "indomaret.co.id" "indomaret.png"
download_logo "INDOMARET" "indomaret.co.id" "indomaret-voucher.png"
download_logo "TIX ID" "tix.id" "tix-id.png"
download_logo "TAPCASH BNI" "bni.co.id" "tapcash-bni.png"
download_logo "MAXIM" "taximaxim.com" "maxim.png"
download_logo "ORANGE TV" "orangetv.co.id" "orange-tv.png"
download_logo "MANDIRI E-TOLL" "bankmandiri.co.id" "mandiri-e-toll-voucher.png"
download_logo "Voucher Garena Shell" "garena.com" "voucher-garena-shell.png"
download_logo "Voucher Megaxus" "megaxus.com" "voucher-megaxus.png"
download_logo "Voucher PB Zepetto" "zepetto.com" "voucher-pb-zepetto.png"
download_logo "Voucher PSN" "playstation.com" "voucher-psn.png"
download_logo "Voucher Razer Gold" "razer.com" "voucher-razer-gold.png"
download_logo "Voucher Roblox" "roblox.com" "voucher-roblox.png"
download_logo "Voucher Valorant" "playvalorant.com" "voucher-valorant.png"
echo ""

# ============================================
# SUMMARY
# ============================================
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "📊 Download Summary:"
echo "  ✅ Success: $SUCCESS"
echo "  ❌ Failed: $FAILED"
echo "  📁 Location: $LOGO_DIR"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""

if [ $SUCCESS -gt 0 ]; then
    echo "🎉 Downloaded $SUCCESS logos!"
    echo ""
    echo "📋 Next steps:"
    echo "  cd /path/to/ryllstore"
    echo "  php artisan categories:upload-from-folder $LOGO_DIR"
    echo ""
    echo "💡 Pro Tip: For BEST quality, download these manually:"
    echo "  • DANA, OVO, GoPay → https://brandfetch.com/"
    echo "  • Popular games → Google Images (high res)"
else
    echo "❌ No logos downloaded successfully."
    echo ""
    echo "💡 Alternative: Download manually from:"
    echo "  - https://brandfetch.com/"
    echo "  - https://seeklogo.com/"
    echo "  - Google Images"
fi
echo ""

# Show file count
FILE_COUNT=$(ls -1 *.png 2>/dev/null | wc -l)
echo "📂 Total files in folder: $FILE_COUNT"
echo ""