<?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('analytics_pageviews', function (Blueprint $table) {
            if (!Schema::hasColumn('analytics_pageviews', 'is_bot')) {
                $table->boolean('is_bot')->default(false)->index()->after('referrer');
            }
            if (!Schema::hasColumn('analytics_pageviews', 'user_agent')) {
                $table->string('user_agent', 500)->nullable()->after('is_bot');
            }
            if (!Schema::hasColumn('analytics_pageviews', 'time_on_page')) {
                $table->unsignedSmallInteger('time_on_page')->default(0)->after('user_agent');
            }
        });
    }

    public function down(): void
    {
        Schema::table('analytics_pageviews', function (Blueprint $table) {
            $table->dropColumn(['is_bot', 'user_agent', 'time_on_page']);
        });
    }
};
