<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        $defaultExists = DB::table('menu_item_image_categories')->where('name', 'Default Category')->whereNull('restaurant_id')->exists();
        if (!$defaultExists) {
            DB::table('menu_item_image_categories')->insert([
                'name' => 'Default Category',
                'description' => 'Default category for admin-uploaded menu item images',
                'restaurant_id' => null,
                'created_at' => now(),
                'updated_at' => now(),
            ]);
        }

        $customExists = DB::table('menu_item_image_categories')->where('name', 'Restaurant Custom Category')->whereNull('restaurant_id')->exists();
        if (!$customExists) {
            DB::table('menu_item_image_categories')->insert([
                'name' => 'Restaurant Custom Category',
                'description' => 'Category for restaurant/branch-uploaded menu item images',
                'restaurant_id' => null,
                'created_at' => now(),
                'updated_at' => now(),
            ]);
        }
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        DB::table('menu_item_image_categories')
            ->whereIn('name', ['Default Category', 'Restaurant Custom Category'])
            ->whereNull('restaurant_id')
            ->delete();
    }
};
