<?php

namespace Database\Seeders;

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

class TradeIndiaCategoriesSeeder extends Seeder
{
    public function run(): void
    {
        // Categories already deleted via tinker

        $categories = [
            'Agriculture' => [
                'Agricultural Machines & Tools',
                'Agriculture & By-product Agents',
                'Agriculture Product Stocks',
                'Agro Chemicals',
                'Agro Products & Commodities',
                'Seeds & Fertilizers',
                'Organic Vegetables',
                'Pulses & Rice',
                'Irrigation System',
                'Tractor Parts',
            ],
            'Apparel & Fashion' => [
                'Men Clothing',
                'Women Clothing',
                'Kids Clothing',
                'Athletic Wear',
                'Baby & Infant Products',
                'Badges & Emblems',
                'Traditional Wear',
                'Western Wear',
                'Uniforms',
            ],
            'Automobile' => [
                'Auto Accessories',
                'Auto Batteries',
                'Auto Bearing',
                'Auto Electronics',
                'Auto Ignition System',
                'Car Parts',
                'Bike Parts',
                'Tyres & Tubes',
            ],
            'Beauty & Cosmetics' => [
                'Makeup Products',
                'Skin Care',
                'Hair Care',
                'Eye Care',
                'Soap & Hand Wash',
                'Personal Care Products',
                'Fragrances & Perfumes',
                'Nail Care',
            ],
            'Bags & Luggage' => [
                'Travel Bags',
                'Handbags',
                'Office Bags',
                'School Bags',
                'Laptop Bags',
                'Sports Bags',
                'Wallets & Purses',
            ],
            'Chemicals' => [
                'Acids',
                'Activated Carbon',
                'Adhesives & Sealants',
                'Aerosols',
                'Industrial Chemicals',
                'Laboratory Chemicals',
            ],
            'Computer Hardware & Software' => [
                'Computers',
                'Computer Accessories',
                'Computer Cables & Connectors',
                'Software Services',
                'Printers & Scanners',
                'Networking Equipment',
            ],
            'Construction & Real Estate' => [
                'AAC Blocks',
                'Aluminum Composite Panels',
                'Architectural Hardware',
                'Bathroom Accessories',
                'Bricks',
                'Cement',
                'Steel & Iron',
                'Tiles & Flooring',
            ],
            'Consumer Electronics' => [
                'Air Conditioner',
                'Air Cooler',
                'Amplifiers',
                'Audio & Video Equipment',
                'Home Appliances',
                'Kitchen Appliances',
                'LED TV',
                'Washing Machines',
            ],
            'Electronics & Electrical Supplies' => [
                'Bulbs & Tubelight',
                'Cable Terminal & Lugs',
                'Cable Trays',
                'Cables & Accessories',
                'Electrical Components',
                'LED Lights',
                'Solar Products',
                'Switches & Sockets',
            ],
            'Energy & Power' => [
                'Batteries',
                'Battery Management Systems',
                'Biofuel',
                'Biogas',
                'Solar Panels',
                'Generators',
                'Inverters',
            ],
            'Food & Beverage' => [
                'Aquatic Products',
                'Beverages',
                'Canned Food',
                'Dairy Products',
                'Dry Fruits',
                'Frozen Food',
                'Snacks',
                'Spices',
                'Sweets',
            ],
            'Footwear & Shoes' => [
                'Men Footwear',
                'Women Footwear',
                'Kids Footwear',
                'Sports Shoes',
                'Sandals & Slippers',
                'Formal Shoes',
                'Safety Shoes',
            ],
            'Furniture' => [
                'Home Furniture',
                'Office Furniture',
                'Bedroom Furniture',
                'Dining Room Furniture',
                'Living Room Furniture',
                'Outdoor Furniture',
                'Antique Furniture',
            ],
            'Gifts & Handicrafts' => [
                'Corporate Gifts',
                'Festival Gifts',
                'Decorative Items',
                'Birthday Gifts',
                'Anniversary Gifts',
                'Religious Crafts',
                'Clocks & Watches',
                'Handmade Crafts',
            ],
            'Health & Personal Care' => [
                'Ayurvedic Products',
                'Health Supplements',
                'Medical Equipment',
                'First Aid',
                'Hygiene Products',
                'Fitness Equipment',
            ],
            'Home Supplies' => [
                'Kitchen Utensils',
                'Home Decor',
                'Cleaning Supplies',
                'Storage Solutions',
                'Gardening Tools',
                'Pet Supplies',
            ],
            'Home Textiles & Furnishings' => [
                'Bed Linen',
                'Curtains',
                'Carpets & Rugs',
                'Bath Towels',
                'Table Linen',
                'Cushions & Pillows',
            ],
            'Hospital & Medical Supplies' => [
                'Surgical Instruments',
                'Diagnostic Equipment',
                'Hospital Furniture',
                'Medical Disposables',
                'Lab Equipment',
                'Wheelchairs',
            ],
            'Hotel Supplies & Equipment' => [
                'Commercial Kitchen Equipment',
                'Bakery Equipment',
                'Bar Accessories',
                'Hotel Furniture',
                'Buffet Equipment',
            ],
            'Industrial Supplies' => [
                'Abrasives',
                'Air Compressors',
                'Conveyors',
                'Cranes & Hoists',
                'Industrial Tools',
                'Safety Equipment',
            ],
            'Mobile Phones & Accessories' => [
                'Mobile Phones',
                'Mobile Covers',
                'Mobile Chargers',
                'Mobile Inner Parts',
                'Earphones & Headphones',
                'Screen Protectors',
            ],
            'Office & School Supplies' => [
                'Calculators',
                'Diaries & Calendars',
                'Education Appliances',
                'Paper Products',
                'Pens & Stationery',
                'Office Furniture',
            ],
            'Packaging & Paper' => [
                'Adhesive Tapes',
                'Boxes & Cartons',
                'Labels & Stickers',
                'Paper Products',
                'Plastic Packaging',
                'Stretch Films',
            ],
            'Pharmaceuticals' => [
                'Ayurvedic Medicines',
                'Generic Medicines',
                'Herbal Products',
                'Surgical Items',
                'Veterinary Products',
            ],
            'Plastics & Products' => [
                'Plastic Containers',
                'Plastic Sheets',
                'Plastic Furniture',
                'Plastic Pipes',
                'Injection Moulding',
            ],
            'Printing & Publishing' => [
                'Books',
                'Printing Services',
                'Binding Machines',
                'Offset Printing',
                'Digital Printing',
            ],
            'Security & Protection' => [
                'CCTV Cameras',
                'Alarm Systems',
                'Fire Extinguishers',
                'Electronic Locks',
                'Access Control',
            ],
            'Sports & Fitness' => [
                'Gym Equipment',
                'Indoor Games',
                'Outdoor Games',
                'Cricket Equipment',
                'Football Equipment',
                'Badminton Equipment',
                'Yoga Products',
            ],
            'Telecommunications' => [
                'Mobile Phones',
                'Telephone Systems',
                'Fax Machines',
                'GPS Devices',
                'Network Equipment',
            ],
            'Textiles & Fabrics' => [
                'Cotton Fabric',
                'Silk Fabric',
                'Polyester Fabric',
                'Linen Fabric',
                'Denim Fabric',
                'Printed Fabric',
            ],
            'Toys & Games' => [
                'Age 0-4 Years',
                'Age 4-8 Years',
                'Age 9-15 Years',
                'Educational Toys',
                'Soft Toys',
                'Action Figures',
                'Board Games',
            ],
            'Transportation' => [
                'Bicycle Parts',
                'Auto Rickshaw Parts',
                'Truck Parts',
                'Aviation Equipment',
                'Marine Equipment',
            ],
            'Others' => [
                'General Products',
                'Miscellaneous',
            ],
        ];

        foreach ($categories as $parentName => $subCategories) {
            $parentSlug = Str::slug($parentName);
            $parent = Category::firstOrCreate(
                ['slug' => $parentSlug],
                [
                    'name' => $parentName,
                    'parent_id' => null,
                    'is_active' => true,
                    'is_featured' => in_array($parentName, ['Apparel & Fashion', 'Electronics & Electrical Supplies', 'Food & Beverage', 'Mobile Phones & Accessories']),
                ]
            );

            foreach ($subCategories as $subName) {
                $childSlug = Str::slug($subName);
                // Make child slug unique by prefixing with parent slug
                $uniqueSlug = $parentSlug . '-' . $childSlug;
                Category::firstOrCreate(
                    ['slug' => $uniqueSlug],
                    [
                        'name' => $subName,
                        'parent_id' => $parent->id,
                        'is_active' => true,
                        'is_featured' => false,
                    ]
                );
            }
        }

        $this->command->info('✅ TradeIndia-style categories created: ' . Category::count() . ' total');
    }
}
