<?php
namespace Database\Seeders;

use App\Models\Category;
use Illuminate\Database\Seeder;
use Illuminate\Support\Str;

class CategorySeeder extends Seeder
{
    public function run(): void
    {
        $categories = [
            ['name' => 'Electronics', 'icon' => 'laptop', 'children' => ['Phones', 'Laptops', 'Tablets', 'Accessories']],
            ['name' => 'Fashion', 'icon' => 'shirt', 'children' => ["Men's Clothing", "Women's Clothing", 'Shoes', 'Bags']],
            ['name' => 'Home & Garden', 'icon' => 'home', 'children' => ['Furniture', 'Kitchen', 'Garden', 'Decor']],
            ['name' => 'Sports', 'icon' => 'dumbbell', 'children' => ['Fitness', 'Outdoor', 'Team Sports']],
            ['name' => 'Books & Media', 'icon' => 'book', 'children' => ['Books', 'Music', 'Movies', 'Software']],
            ['name' => 'Health & Beauty', 'icon' => 'heart', 'children' => ['Skincare', 'Vitamins', 'Personal Care']],
            ['name' => 'Toys & Kids', 'icon' => 'gamepad', 'children' => ['Toys', 'Baby Products', 'School Supplies']],
            ['name' => 'Automotive', 'icon' => 'car', 'children' => ['Parts', 'Accessories', 'Tools']],
        ];

        foreach ($categories as $cat) {
            $parent = Category::create([
                'name'      => $cat['name'],
                'slug'      => Str::slug($cat['name']) . '-' . Str::random(4),
                'icon'      => $cat['icon'],
                'is_active' => true,
                'is_global' => true,
            ]);
            foreach ($cat['children'] as $child) {
                Category::create([
                    'name'      => $child,
                    'slug'      => Str::slug($child) . '-' . Str::random(4),
                    'parent_id' => $parent->id,
                    'is_active' => true,
                    'is_global' => true,
                ]);
            }
        }

        $this->command->info('Categories seeded.');
    }
}
