<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::table('visits', function (Blueprint $table) {
            $table->string('country_code', 2)->nullable()->after('user_agent')->index();
            $table->string('country_name')->nullable()->after('country_code');
        });

        Schema::table('settings', function (Blueprint $table) {
            $table->boolean('admin_contact_notifications_enabled')->default(true)->after('footer_cta_url');
            $table->boolean('user_contact_auto_reply_enabled')->default(true)->after('admin_contact_notifications_enabled');
            $table->string('admin_contact_subject')->nullable()->after('user_contact_auto_reply_enabled');
            $table->text('admin_contact_template')->nullable()->after('admin_contact_subject');
            $table->string('user_contact_subject')->nullable()->after('admin_contact_template');
            $table->text('user_contact_template')->nullable()->after('user_contact_subject');
        });
    }

    public function down(): void
    {
        Schema::table('settings', function (Blueprint $table) {
            $table->dropColumn([
                'admin_contact_notifications_enabled',
                'user_contact_auto_reply_enabled',
                'admin_contact_subject',
                'admin_contact_template',
                'user_contact_subject',
                'user_contact_template',
            ]);
        });

        Schema::table('visits', function (Blueprint $table) {
            $table->dropColumn([
                'country_code',
                'country_name',
            ]);
        });
    }
};
