<?php

namespace Database\Seeders;

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

class ProductSeeder extends Seeder
{
    public function run(): void
    {
        $products = [
            ['Vases & Planters', 'Ceramic Terracotta Vase', 3200, 3800, 'A handcrafted terracotta vase with a matte finish, perfect for dried florals or as a standalone statement piece.'],
            ['Vases & Planters', 'White Ribbed Ceramic Planter', 2200, null, 'Minimalist ribbed planter in soft white ceramic, ideal for indoor plants.'],
            ['Vases & Planters', 'Woven Rattan Basket Planter', 2800, 3200, 'Natural rattan basket planter that adds warm texture to any room.'],
            ['Wall Art & Mirrors', 'Round Rattan Wall Mirror', 5500, 6500, 'A statement round mirror framed in natural woven rattan.'],
            ['Wall Art & Mirrors', 'Abstract Line Art Canvas Print', 4200, null, 'Modern abstract line art printed on premium canvas, ready to hang.'],
            ['Wall Art & Mirrors', 'Gold Framed Wall Mirror', 6800, 7900, 'Elegant gold-framed mirror that adds light and depth to your space.'],
            ['Candles & Fragrance', 'Amber Glass Scented Candle', 1800, null, 'Long-burning soy wax candle in an amber glass jar with warm sandalwood scent.'],
            ['Candles & Fragrance', 'Set of 3 Pillar Candles', 2400, 2900, 'A trio of ivory pillar candles, perfect for centerpieces.'],
            ['Lighting', 'Rattan Pendant Lamp Shade', 7200, 8200, 'Handwoven rattan pendant shade that casts warm, dappled light.'],
            ['Lighting', 'Brass Table Lamp', 6400, null, 'Sleek brass table lamp with a linen shade for soft ambient lighting.'],
            ['Cushions & Throws', 'Linen Textured Cushion Cover', 1500, null, 'Soft linen-blend cushion cover in earthy neutral tones.'],
            ['Cushions & Throws', 'Chunky Knit Throw Blanket', 3600, 4200, 'Oversized chunky knit throw for a cozy, layered living room.'],
            ['Table Décor', 'Marble Coasters Set of 4', 2100, null, 'Elegant marble coasters with a soft-touch cork base.'],
            ['Table Décor', 'Brass Tray with Handles', 3400, 3900, 'Decorative brass tray, perfect for styling coffee tables or vanities.'],
            ['Rugs & Carpets', 'Handwoven Jute Area Rug', 8900, 9900, 'Natural jute area rug that brings texture and warmth to any floor.'],
            ['Clocks', 'Minimalist Wooden Wall Clock', 3100, null, 'Clean, modern wooden wall clock with silent sweep movement.'],
        ];

        foreach ($products as $i => [$categoryName, $name, $price, $comparePrice, $description]) {
            $category = Category::where('name', $categoryName)->first();

            if (! $category) {
                continue;
            }

            Product::firstOrCreate(
                ['slug' => Str::slug($name)],
                [
                    'category_id' => $category->id,
                    'name' => $name,
                    'sku' => 'HHD-'.strtoupper(Str::random(6)),
                    'short_description' => Str::limit($description, 90),
                    'description' => $description,
                    'price' => $price,
                    'compare_price' => $comparePrice,
                    'stock_quantity' => rand(4, 40),
                    'is_active' => true,
                    'is_featured' => $i % 3 === 0,
                ]
            );
        }
    }
}
