<?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('user_followers', function (Blueprint $table) {
            $table->bigIncrements('id');

            // The user being followed
            $table->unsignedBigInteger('user_id');
            // The follower
            $table->unsignedBigInteger('follower_id');

            $table->timestamp('created_at')->useCurrent();

            $table->unique(['user_id', 'follower_id'], 'uq_user_follower');
            $table->index('user_id', 'idx_uf_user');
            $table->index('follower_id', 'idx_uf_follower');

            $table->foreign('user_id')->references('id')->on('users')->cascadeOnDelete();
            $table->foreign('follower_id')->references('id')->on('users')->cascadeOnDelete();
        });
    }

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