<?php

namespace Database\Seeders;

use App\Models\User;
use App\Models\Category;
use App\Models\Product;
use App\Models\Coupon;
use App\Models\Banner;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;

class DatabaseSeeder extends Seeder
{
    public function run(): void
    {
        // ── Admin User ─────────────────────────────────────────────────
        User::create([
            'name'     => 'Bdzoon Admin',
            'email'    => 'admin@bdzoon.com',
            'phone'    => '01849832178',
            'password' => Hash::make('Admin@1234'),
            'role'     => 'admin',
            'loyalty_points' => 0,
            'is_active' => true,
        ]);

        // ── Categories ─────────────────────────────────────────────────
        $cats = [
            ['name' => "Women's Clothing", 'slug' => 'womens-clothing', 'icon' => '🧕', 'sort_order' => 1],
            ['name' => "Men's Clothing",   'slug' => 'mens-clothing',   'icon' => '👔', 'sort_order' => 2],
            ['name' => "Kids' Clothing",   'slug' => 'kids-clothing',   'icon' => '👧', 'sort_order' => 3],
            ['name' => 'Electronics',      'slug' => 'electronics',     'icon' => '📱', 'sort_order' => 4],
            ['name' => 'Gadgets',          'slug' => 'gadgets',         'icon' => '⌚', 'sort_order' => 5],
            ['name' => 'Home & Living',    'slug' => 'home-living',     'icon' => '🏠', 'sort_order' => 6],
        ];

        foreach ($cats as $cat) {
            Category::create(array_merge($cat, ['is_active' => true]));
        }

        $womensCat = Category::where('slug', 'womens-clothing')->first();
        $mensCat   = Category::where('slug', 'mens-clothing')->first();
        $kidsCat   = Category::where('slug', 'kids-clothing')->first();
        $gadgetsCat= Category::where('slug', 'gadgets')->first();
        $elecCat   = Category::where('slug', 'electronics')->first();

        // ── Products ───────────────────────────────────────────────────
        $products = [
            ['name'=>'Kids Cherry Khimar Set KCK116','category_id'=>$womensCat->id,'price'=>850,'sale_price'=>1200,'stock'=>28,'brand'=>'Bdzoon Kids','badge'=>'hot','is_featured'=>true],
            ['name'=>'Cherry Georgette Fabric Khimar','category_id'=>$womensCat->id,'price'=>2200,'stock'=>20,'brand'=>'Bdzoon Fashion','badge'=>'new','is_featured'=>true],
            ['name'=>'Georgette Fabric Abaya Set','category_id'=>$womensCat->id,'price'=>2800,'sale_price'=>3200,'stock'=>15,'brand'=>'Bdzoon Fashion','badge'=>'disc'],
            ['name'=>'Hijab Collection Soft & Stylish','category_id'=>$womensCat->id,'price'=>490,'stock'=>50,'brand'=>'Bdzoon Fashion','badge'=>''],
            ['name'=>'Premium Ambroydary Panjabi','category_id'=>$mensCat->id,'price'=>1390,'stock'=>12,'brand'=>'Bdzoon Men','badge'=>'new'],
            ['name'=>'Tommy Hilfiger Cotton Jacket','category_id'=>$mensCat->id,'price'=>990,'sale_price'=>1200,'stock'=>8,'brand'=>'Bdzoon Men','badge'=>'disc','is_featured'=>true],
            ['name'=>'President Tory Arabian Jubba','category_id'=>$mensCat->id,'price'=>2190,'sale_price'=>2590,'stock'=>15,'brand'=>'Bdzoon Men','badge'=>'hot'],
            ['name'=>'Premium School Bag PSB100','category_id'=>$kidsCat->id,'price'=>1290,'sale_price'=>1490,'stock'=>74,'brand'=>'Bdzoon Kids','badge'=>'hot','is_featured'=>true],
            ['name'=>'Flannel Baby Dress FFB100','category_id'=>$kidsCat->id,'price'=>650,'sale_price'=>850,'stock'=>30,'brand'=>'Bdzoon Kids','badge'=>'disc'],
            ['name'=>'S2000 Promax Smart Watch Combo','category_id'=>$elecCat->id,'price'=>1450,'sale_price'=>1650,'stock'=>3,'brand'=>'Bdzoon Tech','badge'=>'disc','is_featured'=>true],
            ['name'=>'DBBL Smart Watch S3000','category_id'=>$elecCat->id,'price'=>1850,'sale_price'=>2200,'stock'=>10,'brand'=>'Bdzoon Tech','badge'=>'disc'],
            ['name'=>'Liven Turbo Mini Fan','category_id'=>$gadgetsCat->id,'price'=>1200,'sale_price'=>1500,'stock'=>142,'brand'=>'Bdzoon Tech','badge'=>'hot','is_featured'=>true,'is_flash_deal'=>true],

            // ── 30 Demo Products ──────────────────────────────────
            // Women's Clothing
            ['name'=>'Niqab Premium Black Collection','category_id'=>$womensCat->id,'price'=>680,'stock'=>60,'brand'=>'Bdzoon Fashion','badge'=>''],
            ['name'=>'Floral Georgette Saree','category_id'=>$womensCat->id,'price'=>3200,'sale_price'=>3800,'stock'=>20,'brand'=>'Bdzoon Fashion','badge'=>'disc'],
            ['name'=>'Cotton Summer Salwar Kameez','category_id'=>$womensCat->id,'price'=>1100,'stock'=>35,'brand'=>'Bdzoon Fashion','badge'=>'new'],
            ['name'=>'Embroidery Work Kurti Set','category_id'=>$womensCat->id,'price'=>1450,'sale_price'=>1700,'stock'=>18,'brand'=>'Bdzoon Fashion','badge'=>'hot','is_featured'=>true],
            ['name'=>'Silk Dupatta Premium Collection','category_id'=>$womensCat->id,'price'=>550,'stock'=>80,'brand'=>'Bdzoon Fashion','badge'=>''],
            ['name'=>'Party Wear Lehenga Set','category_id'=>$womensCat->id,'price'=>4500,'sale_price'=>5500,'stock'=>8,'brand'=>'Bdzoon Fashion','badge'=>'disc','is_featured'=>true],
            ['name'=>'Abaya Full Length Classic Black','category_id'=>$womensCat->id,'price'=>1850,'sale_price'=>2200,'stock'=>25,'brand'=>'Bdzoon Fashion','badge'=>'hot'],
            ['name'=>'Prayer Hijab Set with Cap','category_id'=>$womensCat->id,'price'=>380,'stock'=>120,'brand'=>'Bdzoon Fashion','badge'=>''],
            // Men's
            ['name'=>'Slim Fit Formal Shirt White','category_id'=>$mensCat->id,'price'=>850,'stock'=>40,'brand'=>'Bdzoon Men','badge'=>'new'],
            ['name'=>'Denim Jeans Premium Fit','category_id'=>$mensCat->id,'price'=>1350,'sale_price'=>1600,'stock'=>30,'brand'=>'Bdzoon Men','badge'=>'disc'],
            ['name'=>'Polo T-Shirt Summer Pack','category_id'=>$mensCat->id,'price'=>1200,'stock'=>50,'brand'=>'Bdzoon Men','badge'=>'new'],
            ['name'=>'Men Formal Pant Office Wear','category_id'=>$mensCat->id,'price'=>950,'sale_price'=>1100,'stock'=>28,'brand'=>'Bdzoon Men','badge'=>'disc'],
            ['name'=>'Eid Special Sherwani Set','category_id'=>$mensCat->id,'price'=>5500,'sale_price'=>6500,'stock'=>12,'brand'=>'Bdzoon Men','badge'=>'hot','is_featured'=>true],
            ['name'=>'Hooded Sweatshirt Winter Warm','category_id'=>$mensCat->id,'price'=>1150,'stock'=>35,'brand'=>'Bdzoon Men','badge'=>'new'],
            // Kids
            ['name'=>'Boys School Uniform Set','category_id'=>$kidsCat->id,'price'=>850,'sale_price'=>1000,'stock'=>55,'brand'=>'Bdzoon Kids','badge'=>'hot'],
            ['name'=>'Girls Frock Party Dress','category_id'=>$kidsCat->id,'price'=>950,'sale_price'=>1200,'stock'=>30,'brand'=>'Bdzoon Kids','badge'=>'hot','is_featured'=>true],
            ['name'=>'Kids Winter Jacket Warm','category_id'=>$kidsCat->id,'price'=>780,'sale_price'=>950,'stock'=>20,'brand'=>'Bdzoon Kids','badge'=>'disc'],
            ['name'=>'Baby Romper Set Newborn','category_id'=>$kidsCat->id,'price'=>550,'stock'=>45,'brand'=>'Bdzoon Kids','badge'=>'new'],
            ['name'=>'Boys Casual Jogger Pant','category_id'=>$kidsCat->id,'price'=>480,'stock'=>60,'brand'=>'Bdzoon Kids','badge'=>''],
            // Electronics
            ['name'=>'Android Smart TV Box 4K','category_id'=>$elecCat->id,'price'=>2800,'sale_price'=>3200,'stock'=>15,'brand'=>'Bdzoon Tech','badge'=>'hot','is_featured'=>true],
            ['name'=>'Bluetooth Speaker Portable','category_id'=>$elecCat->id,'price'=>1800,'sale_price'=>2100,'stock'=>28,'brand'=>'Bdzoon Tech','badge'=>'disc'],
            ['name'=>'Power Bank 20000mAh Fast Charge','category_id'=>$elecCat->id,'price'=>2200,'stock'=>35,'brand'=>'Bdzoon Tech','badge'=>'new'],
            ['name'=>'USB-C Charging Cable 3-Pack','category_id'=>$elecCat->id,'price'=>480,'stock'=>200,'brand'=>'Bdzoon Tech','badge'=>''],
            ['name'=>'Wireless Mouse & Keyboard Combo','category_id'=>$elecCat->id,'price'=>1650,'sale_price'=>1900,'stock'=>20,'brand'=>'Bdzoon Tech','badge'=>'disc'],
            // Gadgets
            ['name'=>'Smart LED Strip Light RGB','category_id'=>$gadgetsCat->id,'price'=>850,'sale_price'=>1100,'stock'=>60,'brand'=>'Bdzoon Tech','badge'=>'hot','is_featured'=>true],
            ['name'=>'Digital Kitchen Scale 5kg','category_id'=>$gadgetsCat->id,'price'=>480,'stock'=>55,'brand'=>'Bdzoon Tech','badge'=>''],
            ['name'=>'Mini Projector Portable HD','category_id'=>$gadgetsCat->id,'price'=>4200,'sale_price'=>5000,'stock'=>10,'brand'=>'Bdzoon Tech','badge'=>'disc','is_featured'=>true],
            ['name'=>'Car Phone Holder Magnetic','category_id'=>$gadgetsCat->id,'price'=>350,'stock'=>150,'brand'=>'Bdzoon Tech','badge'=>''],
            ['name'=>'Smart Plug WiFi Remote Control','category_id'=>$gadgetsCat->id,'price'=>650,'sale_price'=>780,'stock'=>80,'brand'=>'Bdzoon Tech','badge'=>'new'],
        ];

        foreach ($products as $p) {
            Product::create(array_merge($p, [
                'slug'       => Str::slug($p['name']) . '-' . Str::random(4),
                'is_active'  => true,
                'images'     => [],
            ]));
        }

        // ── Coupons ────────────────────────────────────────────────────
        $coupons = [
            ['code'=>'BDZOON10','type'=>'percent','value'=>10,'min_order'=>0,'usage_limit'=>null,'is_active'=>true],
            ['code'=>'SAVE50',  'type'=>'flat',   'value'=>50,'min_order'=>500,'usage_limit'=>500,'is_active'=>true],
            ['code'=>'FREESHIP','type'=>'shipping','value'=>80,'min_order'=>0,'usage_limit'=>200,'is_active'=>true],
        ];
        foreach ($coupons as $c) Coupon::create($c);

        // ── Banners ────────────────────────────────────────────────────
        Banner::create(['title'=>"Men's Collection Banner",'image'=>'/images/banner1.jpg','type'=>'hero','sort_order'=>1,'is_active'=>true]);
        Banner::create(['title'=>"Women's Collection Banner",'image'=>'/images/banner2.jpg','type'=>'hero','sort_order'=>2,'is_active'=>true]);
        Banner::create(['title'=>"Kids' Collection Banner",'image'=>'/images/banner3.jpg','type'=>'hero','sort_order'=>3,'is_active'=>true]);

        $this->command->info('✓ Bdzoon database seeded successfully!');
        $this->command->info('  Admin: admin@bdzoon.com / Admin@1234');
    }
}
