<?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('offerwall_clicks', function (Blueprint $table) {
            $table->foreignId('lead_id')->nullable()->after('provider_offer_id')->constrained()->nullOnDelete();
            $table->timestamp('completed_at')->nullable()->after('lead_id');
            $table->index(['user_id', 'completed_at', 'created_at']);
        });
    }

    public function down(): void
    {
        Schema::table('offerwall_clicks', function (Blueprint $table) {
            $table->dropIndex(['user_id', 'completed_at', 'created_at']);
            $table->dropConstrainedForeignId('lead_id');
            $table->dropColumn('completed_at');
        });
    }
};
