<?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('profile_visits', function (Blueprint $table) {
            $table->id();
            $table->foreignId('profile_user_id')->constrained('users')->cascadeOnDelete();
            $table->foreignId('visitor_user_id')->nullable()->constrained('users')->nullOnDelete();
            $table->string('device_id', 64)->nullable();
            $table->foreignId('source_video_id')->nullable()->constrained('videos')->nullOnDelete();
            $table->string('ip_address', 45)->nullable();
            $table->string('country', 2)->nullable();
            $table->timestamp('created_at')->useCurrent();

            $table->index(['profile_user_id', 'created_at']);
            $table->index('source_video_id');
        });
    }

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