<?php

namespace Database\Seeders;

use App\Models\Product;
use App\Models\Category;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;

class ProductSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        $products = [
            // Burgers
            [
                'category_name' => 'Burgers',
                'name' => 'Classic Cheeseburger',
                'slug' => 'classic-cheeseburger',
                'description' => 'Juicy classic burger with melted cheese',
                'price' => 9.99,
                'stock' => 50,
                'status' => true,
            ],
            [
                'category_name' => 'Burgers',
                'name' => 'Bacon Burger',
                'slug' => 'bacon-burger',
                'description' => 'Burger with crispy bacon and special sauce',
                'price' => 11.99,
                'stock' => 45,
                'status' => true,
            ],
            // Pizza
            [
                'category_name' => 'Pizza',
                'name' => 'Margherita Pizza',
                'slug' => 'margherita-pizza',
                'description' => 'Traditional pizza with tomato, mozzarella and basil',
                'price' => 12.99,
                'stock' => 30,
                'status' => true,
            ],
            [
                'category_name' => 'Pizza',
                'name' => 'Pepperoni Pizza',
                'slug' => 'pepperoni-pizza',
                'description' => 'Pizza with mozzarella and pepperoni',
                'price' => 13.99,
                'stock' => 35,
                'status' => true,
            ],
            // Pasta
            [
                'category_name' => 'Pasta',
                'name' => 'Spaghetti Carbonara',
                'slug' => 'spaghetti-carbonara',
                'description' => 'Classic italian pasta with creamy sauce',
                'price' => 10.99,
                'stock' => 40,
                'status' => true,
            ],
            [
                'category_name' => 'Pasta',
                'name' => 'Fettuccine Alfredo',
                'slug' => 'fettuccine-alfredo',
                'description' => 'Creamy alfredo sauce with fettuccine',
                'price' => 11.99,
                'stock' => 38,
                'status' => true,
            ],
            // Desserts
            [
                'category_name' => 'Desserts',
                'name' => 'Chocolate Cake',
                'slug' => 'chocolate-cake',
                'description' => 'Rich chocolate cake with frosting',
                'price' => 6.99,
                'stock' => 25,
                'status' => true,
            ],
            [
                'category_name' => 'Desserts',
                'name' => 'Ice Cream Sundae',
                'slug' => 'ice-cream-sundae',
                'description' => 'Ice cream with toppings and syrup',
                'price' => 5.99,
                'stock' => 50,
                'status' => true,
            ],
        ];

        foreach ($products as $product) {
            $category = Category::where('name', $product['category_name'])->first();
            if ($category) {
                Product::firstOrCreate(
                    ['slug' => $product['slug']],
                    [
                        'category_id' => $category->id,
                        'name' => $product['name'],
                        'description' => $product['description'],
                        'price' => $product['price'],
                        'stock' => $product['stock'],
                        'status' => $product['status'],
                    ]
                );
            }
        }
    }
}
