<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::table('visitors', function (Blueprint $table) {
            // Check if columns don't already exist before adding them
            if (!Schema::hasColumn('visitors', 'page_views')) {
                $table->unsignedInteger('page_views')->default(1)->after('source');
            }
            if (!Schema::hasColumn('visitors', 'session_duration')) {
                $table->unsignedInteger('session_duration')->default(0)->after('page_views'); // in seconds
            }
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('visitors', function (Blueprint $table) {
            $table->dropColumn(['page_views', 'session_duration']);
        });
    }
};
