<?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('customer_activities', function (Blueprint $table) {
            if (!Schema::hasColumn('customer_activities', 'reference_no')) {
                $table->string('reference_no')->nullable()->index()->after('customer_id');
            }
            if (!Schema::hasColumn('customer_activities', 'location')) {
                $table->string('location')->nullable()->after('description');
            }
            if (!Schema::hasColumn('customer_activities', 'meeting_link')) {
                $table->string('meeting_link')->nullable()->after('location');
            }
            if (!Schema::hasColumn('customer_activities', 'metadata')) {
                $table->json('metadata')->nullable()->after('direction');
            }
        });
    }

    public function down(): void
    {
        Schema::table('customer_activities', function (Blueprint $table) {
            $table->dropColumn(['reference_no', 'location', 'meeting_link', 'metadata']);
        });
    }
};
