<?php

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

class AddLiveChatControlsToSettingsTable extends Migration
{
    public function up()
    {
        Schema::table('settings', function (Blueprint $table) {
            if (!Schema::hasColumn('settings', 'live_chat_enabled')) {
                $table->string('live_chat_enabled')->default('on')->after('tawk_to');
            }

            if (!Schema::hasColumn('settings', 'footer_injection_code')) {
                $table->text('footer_injection_code')->nullable()->after('live_chat_enabled');
            }
        });
    }

    public function down()
    {
        Schema::table('settings', function (Blueprint $table) {
            if (Schema::hasColumn('settings', 'footer_injection_code')) {
                $table->dropColumn('footer_injection_code');
            }

            if (Schema::hasColumn('settings', 'live_chat_enabled')) {
                $table->dropColumn('live_chat_enabled');
            }
        });
    }
}
