<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;

class ComprehensiveCategoryProductSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        $timestamp = now();

        echo "🚀 Starting comprehensive category & product seeding...\n\n";

        // ========================================
        // GAME CATEGORIES
        // ========================================
        $gameCategories = [
            [
                'name' => 'Mobile Legends',
                'slug' => 'mobile-legends',
                'brand_code' => 'MOBILELEGEND',
                'category_type' => 'game',
                'description' => 'Top up diamond Mobile Legends termurah dan tercepat. Proses otomatis 1-5 menit!',
                'icon' => 'fas fa-gamepad',
                'image' => 'https://i.imgur.com/wkxKGHT.png',
                'sort_order' => 1,
            ],
            [
                'name' => 'Free Fire',
                'slug' => 'free-fire',
                'brand_code' => 'FREEFIRE',
                'category_type' => 'game',
                'description' => 'Top up diamond Free Fire murah dan aman. Proses instant tanpa perlu login!',
                'icon' => 'fas fa-fire',
                'image' => 'https://i.imgur.com/9xvZJKm.png',
                'sort_order' => 2,
            ],
            [
                'name' => 'PUBG Mobile',
                'slug' => 'pubg-mobile',
                'brand_code' => 'PUBGM',
                'category_type' => 'game',
                'description' => 'Top up UC PUBG Mobile termurah. Bonus langsung masuk ke akun game!',
                'icon' => 'fas fa-crosshairs',
                'image' => 'https://i.imgur.com/xK8mL9P.png',
                'sort_order' => 3,
            ],
            [
                'name' => 'Genshin Impact',
                'slug' => 'genshin-impact',
                'brand_code' => 'GENSHIN',
                'category_type' => 'game',
                'description' => 'Top up Genesis Crystal Genshin Impact. Proses cepat dan terpercaya!',
                'icon' => 'fas fa-gem',
                'image' => 'https://i.imgur.com/2tY5xZm.png',
                'sort_order' => 4,
            ],
            [
                'name' => 'Honkai Star Rail',
                'slug' => 'honkai-star-rail',
                'brand_code' => 'HONKAI',
                'category_type' => 'game',
                'description' => 'Top up Oneiric Shard Honkai Star Rail. Proses instant 24/7!',
                'icon' => 'fas fa-star',
                'image' => 'https://i.imgur.com/5xK3wYr.png',
                'sort_order' => 5,
            ],
        ];

        // ========================================
        // E-WALLET CATEGORIES
        // ========================================
        $ewalletCategories = [
            [
                'name' => 'GoPay',
                'slug' => 'gopay',
                'brand_code' => 'GOPAY',
                'category_type' => 'ewallet',
                'description' => 'Top up saldo GoPay instant. Cashback hingga 10rb setiap transaksi!',
                'icon' => 'fas fa-wallet',
                'image' => 'https://upload.wikimedia.org/wikipedia/commons/thumb/8/86/Gopay_logo.svg/1200px-Gopay_logo.svg.png',
                'sort_order' => 20,
            ],
            [
                'name' => 'OVO',
                'slug' => 'ovo',
                'brand_code' => 'OVO',
                'category_type' => 'ewallet',
                'description' => 'Top up OVO murah dan cepat. Proses otomatis dalam hitungan detik!',
                'icon' => 'fas fa-wallet',
                'image' => 'https://upload.wikimedia.org/wikipedia/commons/thumb/e/eb/Logo_ovo_purple.svg/1200px-Logo_ovo_purple.svg.png',
                'sort_order' => 21,
            ],
            [
                'name' => 'DANA',
                'slug' => 'dana',
                'brand_code' => 'DANA',
                'category_type' => 'ewallet',
                'description' => 'Top up DANA termurah dan terpercaya. Saldo langsung masuk ke akun!',
                'icon' => 'fas fa-wallet',
                'image' => 'https://upload.wikimedia.org/wikipedia/commons/thumb/7/72/Logo_dana_blue.svg/1200px-Logo_dana_blue.svg.png',
                'sort_order' => 22,
            ],
            [
                'name' => 'ShopeePay',
                'slug' => 'shopeepay',
                'brand_code' => 'SHOPEE',
                'category_type' => 'ewallet',
                'description' => 'Top up ShopeePay instant. Gratis biaya admin untuk transaksi tertentu!',
                'icon' => 'fas fa-wallet',
                'image' => 'https://upload.wikimedia.org/wikipedia/commons/thumb/0/0e/Shopee_logo.svg/1200px-Shopee_logo.svg.png',
                'sort_order' => 23,
            ],
            [
                'name' => 'LinkAja',
                'slug' => 'linkaja',
                'brand_code' => 'LINKAJA',
                'category_type' => 'ewallet',
                'description' => 'Top up LinkAja murah dan aman. Proses cepat 24 jam non-stop!',
                'icon' => 'fas fa-wallet',
                'image' => 'https://upload.wikimedia.org/wikipedia/commons/thumb/8/85/LinkAja.svg/1200px-LinkAja.svg.png',
                'sort_order' => 24,
            ],
        ];

        // ========================================
        // PULSA CATEGORIES (Additional operators)
        // ========================================
        $pulsaCategories = [
            [
                'name' => 'Pulsa Indosat',
                'slug' => 'pulsa-indosat',
                'brand_code' => 'INDOSAT',
                'category_type' => 'pulsa',
                'description' => 'Top up pulsa Indosat termurah. Proses instant 24/7!',
                'icon' => 'fas fa-mobile-alt',
                'image' => 'https://upload.wikimedia.org/wikipedia/commons/thumb/c/c4/Indosat_Ooredoo_logo.svg/1200px-Indosat_Ooredoo_logo.svg.png',
                'sort_order' => 30,
            ],
            [
                'name' => 'Pulsa Tri',
                'slug' => 'pulsa-tri',
                'brand_code' => 'TRI',
                'category_type' => 'pulsa',
                'description' => 'Top up pulsa Tri termurah. Proses otomatis dan cepat!',
                'icon' => 'fas fa-mobile-alt',
                'image' => 'https://upload.wikimedia.org/wikipedia/commons/thumb/8/8c/3_%28Tri%29_logo.svg/1200px-3_%28Tri%29_logo.svg.png',
                'sort_order' => 31,
            ],
            [
                'name' => 'Pulsa Smartfren',
                'slug' => 'pulsa-smartfren',
                'brand_code' => 'SMARTFREN',
                'category_type' => 'pulsa',
                'description' => 'Top up pulsa Smartfren termurah. Proses instant dan aman!',
                'icon' => 'fas fa-mobile-alt',
                'image' => 'https://upload.wikimedia.org/wikipedia/commons/thumb/c/c6/Smartfren_logo.svg/1200px-Smartfren_logo.svg.png',
                'sort_order' => 32,
            ],
        ];

        // Merge all categories
        $allCategories = array_merge($gameCategories, $ewalletCategories, $pulsaCategories);

        // Insert categories
        foreach ($allCategories as $category) {
            $category['is_active'] = true;
            $category['created_at'] = $timestamp;
            $category['updated_at'] = $timestamp;
            
            $exists = DB::table('categories')->where('slug', $category['slug'])->exists();
            
            if (!$exists) {
                DB::table('categories')->insert($category);
                echo "✅ Created category: {$category['name']}\n";
            } else {
                echo "⚠️  Category exists: {$category['name']}\n";
            }
        }

        echo "\n📦 Categories seeding completed!\n";
        echo "🔄 Now you should run: php artisan digiflazz:sync\n";
        echo "   This will fetch products from Digiflazz API and match them to categories based on brand_code\n\n";
    }
}
