<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up()
    {
        if (!Schema::hasColumn('settings', 'logo') && !Schema::hasColumn('settings', 'icon')) {
            Schema::table('settings', function (Blueprint $table) {
                $table->string('logo')->nullable()->after('value');
                $table->string('icon')->nullable()->after('logo');
            });

            // Insert default settings for logo and icon
            DB::table('settings')->insert([
                [
                    'key' => 'logo',
                    'value' => null,
                    'created_at' => now(),
                    'updated_at' => now()
                ],
                [
                    'key' => 'icon',
                    'value' => null,
                    'created_at' => now(),
                    'updated_at' => now()
                ]
            ]);
        }
    }

    public function down()
    {
        Schema::table('settings', function (Blueprint $table) {
            // First delete the settings entries
            DB::table('settings')->whereIn('key', ['logo', 'icon'])->delete();
            
            // Then drop the columns
            $table->dropColumn(['logo', 'icon']);
        });
    }
};