<?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('leads', function (Blueprint $table) {
            $table->string('utm_source', 120)->nullable()->after('source');
            $table->string('utm_content', 190)->nullable()->after('utm_campaign');
            $table->string('utm_term', 190)->nullable()->after('utm_content');
            $table->string('fbclid', 255)->nullable()->after('utm_term');
            $table->string('gclid', 255)->nullable()->after('fbclid');
            $table->string('referrer_url', 500)->nullable()->after('page_url');
            $table->string('landing_page', 500)->nullable()->after('referrer_url');
        });

        Schema::table('contact_submissions', function (Blueprint $table) {
            $table->string('utm_source', 120)->nullable()->after('source');
            $table->string('utm_medium', 120)->nullable()->after('utm_source');
            $table->string('utm_campaign', 190)->nullable()->after('utm_medium');
            $table->string('utm_content', 190)->nullable()->after('utm_campaign');
            $table->string('utm_term', 190)->nullable()->after('utm_content');
            $table->string('fbclid', 255)->nullable()->after('utm_term');
            $table->string('gclid', 255)->nullable()->after('fbclid');
            $table->string('referrer_url', 500)->nullable()->after('page_url');
            $table->string('landing_page', 500)->nullable()->after('referrer_url');
        });

        Schema::table('event_registrations', function (Blueprint $table) {
            $table->string('source', 120)->nullable()->after('status');
            $table->string('utm_source', 120)->nullable()->after('source');
            $table->string('utm_medium', 120)->nullable()->after('utm_source');
            $table->string('utm_campaign', 190)->nullable()->after('utm_medium');
            $table->string('utm_content', 190)->nullable()->after('utm_campaign');
            $table->string('utm_term', 190)->nullable()->after('utm_content');
            $table->string('fbclid', 255)->nullable()->after('utm_term');
            $table->string('gclid', 255)->nullable()->after('fbclid');
            $table->string('page_url', 500)->nullable()->after('gclid');
            $table->string('referrer_url', 500)->nullable()->after('page_url');
            $table->string('landing_page', 500)->nullable()->after('referrer_url');
        });
    }

    public function down(): void
    {
        Schema::table('event_registrations', function (Blueprint $table) {
            $table->dropColumn(['source', 'utm_source', 'utm_medium', 'utm_campaign', 'utm_content', 'utm_term', 'fbclid', 'gclid', 'page_url', 'referrer_url', 'landing_page']);
        });

        Schema::table('contact_submissions', function (Blueprint $table) {
            $table->dropColumn(['utm_source', 'utm_medium', 'utm_campaign', 'utm_content', 'utm_term', 'fbclid', 'gclid', 'referrer_url', 'landing_page']);
        });

        Schema::table('leads', function (Blueprint $table) {
            $table->dropColumn(['utm_source', 'utm_content', 'utm_term', 'fbclid', 'gclid', 'referrer_url', 'landing_page']);
        });
    }
};
