<?php

namespace Database\Seeders;

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

class SubcategorySeeder extends Seeder
{
    public function run(): void
    {
        $home = Category::where('slug', 'home')->first();
        if ($home) {
            $subs = [
                ['name' => 'Living Room', 'description' => 'Sofas, coffee tables, entertainment units and more'],
                ['name' => 'Bedroom', 'description' => 'Beds, dressers, nightstands and bedding'],
                ['name' => 'Kitchen & Dining', 'description' => 'Cookware, dinnerware, utensils and dining sets'],
                ['name' => 'Bathroom', 'description' => 'Towels, shower curtains, organizers and accessories'],
                ['name' => 'Home Decor', 'description' => 'Wall art, vases, candles and decorative accents'],
                ['name' => 'Lighting', 'description' => 'Lamps, ceiling lights, chandeliers and bulbs'],
                ['name' => 'Cleaning Supplies', 'description' => 'Cleaning tools, detergents, mops and brooms'],
                ['name' => 'Storage & Organization', 'description' => 'Shelves, bins, baskets and closet organizers'],
            ];
            foreach ($subs as $sub) {
                Subcategory::create([
                    'category_id' => $home->id,
                    'name' => $sub['name'],
                    'slug' => Str::slug($sub['name']),
                    'description' => $sub['description'],
                    'status' => true,
                ]);
            }
        }

        $beauty = Category::where('slug', 'beauty-personal-care')->first();
        if ($beauty) {
            $subs = [
                ['name' => 'Skincare', 'description' => 'Moisturizers, serums, cleansers and treatments'],
                ['name' => 'Makeup', 'description' => 'Foundation, lipstick, eyeshadow and more'],
                ['name' => 'Fragrance', 'description' => 'Perfumes, colognes and body sprays'],
                ['name' => 'Hair Care', 'description' => 'Shampoo, conditioner, styling products'],
            ];
            foreach ($subs as $sub) {
                Subcategory::create([
                    'category_id' => $beauty->id,
                    'name' => $sub['name'],
                    'slug' => Str::slug($sub['name']),
                    'description' => $sub['description'],
                    'status' => true,
                ]);
            }
        }

        $frozen = Category::where('slug', 'frozen-foods')->first();
        if ($frozen) {
            $subs = [
                ['name' => 'Frozen Meat', 'description' => 'Beef, chicken, pork and lamb'],
                ['name' => 'Frozen Vegetables', 'description' => 'Mixed vegetables, peas, spinach and more'],
                ['name' => 'Ice Cream & Desserts', 'description' => 'Ice cream, frozen yogurt and sweet treats'],
                ['name' => 'Frozen Seafood', 'description' => 'Fish, shrimp, crab and shellfish'],
            ];
            foreach ($subs as $sub) {
                Subcategory::create([
                    'category_id' => $frozen->id,
                    'name' => $sub['name'],
                    'slug' => Str::slug($sub['name']),
                    'description' => $sub['description'],
                    'status' => true,
                ]);
            }
        }

        $groceries = Category::where('slug', 'food-groceries')->first();
        if ($groceries) {
            $subs = [
                ['name' => 'Rice & Grains', 'description' => 'White rice, brown rice, quinoa and oats'],
                ['name' => 'Pasta & Noodles', 'description' => 'Spaghetti, macaroni, instant noodles'],
                ['name' => 'Canned Goods', 'description' => 'Tomatoes, beans, soup and vegetables'],
                ['name' => 'Cooking Oil', 'description' => 'Vegetable oil, olive oil, coconut oil'],
            ];
            foreach ($subs as $sub) {
                Subcategory::create([
                    'category_id' => $groceries->id,
                    'name' => $sub['name'],
                    'slug' => Str::slug($sub['name']),
                    'description' => $sub['description'],
                    'status' => true,
                ]);
            }
        }
    }
}
