<?php

namespace Database\Seeders;

use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;

class ProductSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        $categories = \App\Models\Category::all();
        
        $products = [
            [
                'name' => 'Organic Red Carrots',
                'slug' => 'organic-red-carrots',
                'description' => 'Premium farm-fresh organic red carrots, rich in vitamins and minerals.',
                'price' => 2.99,
                'discount_price' => 2.49,
                'stock' => 150,
                'image' => 'https://placehold.co/600x600?text=Organic+Red+Carrots',
                'is_featured' => true,
            ],
            [
                'name' => 'Fresh Green Broccoli',
                'slug' => 'fresh-green-broccoli',
                'description' => 'Healthy and crunchy green broccoli, harvested daily from local farms.',
                'price' => 3.49,
                'discount_price' => null,
                'stock' => 80,
                'image' => 'https://placehold.co/600x600?text=Fresh+Green+Broccoli',
                'is_featured' => true,
            ],
            [
                'name' => 'Premium Fuji Apples',
                'slug' => 'premium-fuji-apples',
                'description' => 'Sweet and crisp Fuji apples, perfect for snacking or desserts.',
                'price' => 5.99,
                'discount_price' => 4.99,
                'stock' => 200,
                'image' => 'https://placehold.co/600x600?text=Premium+Fuji+Apples',
                'is_featured' => false,
            ],
            [
                'name' => 'Farm Fresh Milk (1L)',
                'slug' => 'farm-fresh-milk-1l',
                'description' => 'Pure and nutritious cow milk, delivered straight from the farm.',
                'price' => 1.99,
                'discount_price' => null,
                'stock' => 300,
                'image' => 'https://placehold.co/600x600?text=Farm+Fresh+Milk',
                'is_featured' => true,
            ],
        ];

        foreach ($products as $prod) {
            $prod['category_id'] = $categories->random()->id;
            \App\Models\Product::updateOrCreate(['slug' => $prod['slug']], $prod);
        }
    }
}
