<?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::create('offerwall_clicks', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained()->cascadeOnDelete();
            $table->foreignId('offerwall_id')->nullable()->constrained()->nullOnDelete();
            $table->string('provider_name');
            $table->string('launch_mode')->default('iframe');
            $table->string('ip')->nullable();
            $table->string('user_agent')->nullable();
            $table->timestamps();

            $table->index(['offerwall_id', 'created_at']);
            $table->index(['provider_name', 'created_at']);
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('offerwall_clicks');
    }
};
