<?php

namespace Database\Seeders;

use App\Models\MenuCategory;
use App\Models\MenuItem;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;

class MenuSeeder extends Seeder
{
    public function run()
    {
        // Nonaktifkan foreign key checks
        DB::statement('SET FOREIGN_KEY_CHECKS=0;');
        
        // Clear existing data
        MenuItem::truncate();
        MenuCategory::truncate();
        
        // Aktifkan kembali foreign key checks
        DB::statement('SET FOREIGN_KEY_CHECKS=1;');
        
        // Create Categories with images
        $categories = [
            [
                'name' => 'BEVERAGES',
                'description' => '',
                'icon' => 'fa-glass-whiskey',
                'order' => 1,
                'is_active' => true,
                'items' => [
                    ['name' => 'Mark', 'description' => 'Minuman markisa spesial', 'price' => 12000, 'is_active' => true],
                    ['name' => 'fork Manis', 'description' => 'Minuman manis segar', 'price' => 8000, 'is_active' => true],
                    ['name' => 'brok', 'description' => 'Minuman brokoli sehat', 'price' => 10000, 'is_active' => true],
                    ['name' => 'Alpukat', 'description' => 'Jus alpukat premium', 'price' => 18000, 'is_active' => true],
                    ['name' => 'dang Jaho', 'description' => 'Minuman tradisional', 'price' => 12000, 'is_active' => true],
                ]
            ],
            [
                'name' => 'APPETIZER & SOUP',
                'description' => '',
                'icon' => 'fa-utensil-spoon',
                'order' => 2,
                'is_active' => true,
                'items' => [
                    ['name' => 'Soto Ayam', 'description' => 'Soto ayam kampung spesial', 'price' => 25000, 'is_active' => true],
                    ['name' => 'Sup Jagung', 'description' => 'Sup jagung dengan krim', 'price' => 22000, 'is_active' => true],
                    ['name' => 'Bakso Kuan', 'description' => 'Bakso daging sapi pilihan', 'price' => 30000, 'is_active' => true],
                    ['name' => 'Pop Bunlut', 'description' => 'Appetizer modern', 'price' => 45000, 'is_active' => true],
                    ['name' => 'Rawon', 'description' => 'Rawon daging sapi hitam', 'price' => 35000, 'is_active' => true],
                ]
            ],
            [
                'name' => 'MAIN COURSE',
                'description' => '',
                'icon' => 'fa-drumstick-bite',
                'order' => 3,
                'is_active' => true,
                'items' => [
                    ['name' => 'Nasi Goreng Special', 'description' => 'Nasi goreng dengan seafood', 'price' => 35000, 'is_active' => true],
                    ['name' => 'Mie Goreng Seafood', 'description' => 'Mie goreng dengan cumi dan udang', 'price' => 40000, 'is_active' => true],
                    ['name' => 'Ayam Bakar Kecap', 'description' => 'Ayam bakar kecap manis', 'price' => 75000, 'is_active' => true],
                    ['name' => 'Ikan Gurame Goreng', 'description' => 'Gurame goreng krispi', 'price' => 55000, 'is_active' => true],
                    ['name' => 'Sate Kambing', 'description' => 'Sate kambing bumbu kacang', 'price' => 45000, 'is_active' => true],
                ]
            ],
            [
                'name' => 'DESSERTS',
                'description' => '',
                'icon' => 'fa-ice-cream',
                'order' => 4,
                'is_active' => true,
                'items' => [
                    ['name' => 'Puding Coklat', 'description' => 'Puding coklat Belgia', 'price' => 25000, 'is_active' => true],
                    ['name' => 'Kue Lapis', 'description' => 'Kue lapis tradisional', 'price' => 20000, 'is_active' => true],
                    ['name' => 'Cheesecake', 'description' => 'Cheesecake New York style', 'price' => 45000, 'is_active' => true],
                    ['name' => 'Brownies', 'description' => 'Brownies coklat premium', 'price' => 30000, 'is_active' => true],
                    ['name' => 'Es Krim Vanilla', 'description' => 'Es krim vanilla homemade', 'price' => 35000, 'is_active' => true],
                ]
                ],
            [
                'name' => 'TEST',
                'description' => '',
                'icon' => 'fa-ice-cream',
                'order' => 4,
                'is_active' => true,
                'items' => [
                    ['name' => 'Puding Coklat', 'description' => 'Puding coklat Belgia', 'price' => 25000, 'is_active' => true],
                    ['name' => 'Kue Lapis', 'description' => 'Kue lapis tradisional', 'price' => 20000, 'is_active' => true],
                    ['name' => 'Cheesecake', 'description' => 'Cheesecake New York style', 'price' => 45000, 'is_active' => true],
                    ['name' => 'Brownies', 'description' => 'Brownies coklat premium', 'price' => 30000, 'is_active' => true],
                    ['name' => 'Es Krim Vanilla', 'description' => 'Es krim vanilla homemade', 'price' => 35000, 'is_active' => true],
                ]
                ],
                [
                'name' => 'DESSERTS222',
                'description' => '',
                'icon' => 'fa-ice-cream',
                'order' => 4,
                'is_active' => true,
                'items' => [
                    ['name' => 'Puding Coklat', 'description' => 'Puding coklat Belgia', 'price' => 25000, 'is_active' => true],
                    ['name' => 'Kue Lapis', 'description' => 'Kue lapis tradisional', 'price' => 20000, 'is_active' => true],
                    ['name' => 'Cheesecake', 'description' => 'Cheesecake New York style', 'price' => 45000, 'is_active' => true],
                    ['name' => 'Brownies', 'description' => 'Brownies coklat premium', 'price' => 30000, 'is_active' => true],
                    ['name' => 'Es Krim Vanilla', 'description' => 'Es krim vanilla homemade', 'price' => 35000, 'is_active' => true],
                ]
            ]
        ];
        
        foreach ($categories as $categoryData) {
            // Create category
            $category = MenuCategory::create([
                'name' => $categoryData['name'],
                'description' => $categoryData['description'],
                'icon' => $categoryData['icon'],
                'order' => $categoryData['order'],
                'is_active' => $categoryData['is_active'],
                'image' => null, // You can add image paths here if you have images
            ]);
            
            // Create items for this category
            foreach ($categoryData['items'] as $index => $itemData) {
                MenuItem::create([
                    'category_id' => $category->id,
                    'name' => $itemData['name'],
                    'description' => $itemData['description'],
                    'price' => $itemData['price'],
                    'order' => $index,
                    'is_active' => $itemData['is_active'],
                ]);
            }
        }
        
        $this->command->info('Menu data seeded successfully!');
        $this->command->info('Total Categories: ' . MenuCategory::count());
        $this->command->info('Total Items: ' . MenuItem::count());
    }
}