<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('report_entities', function (Blueprint $table) {
            $table->id();
            $table->foreignId('report_id')->constrained()->cascadeOnDelete();
            $table->string('model_class');
            $table->string('alias', 50)->nullable();
            $table->enum('join_type', ['base', 'join', 'leftJoin', 'rightJoin'])->default('base');
            $table->string('join_first', 100)->nullable();
            $table->string('join_operator', 10)->nullable();
            $table->string('join_second', 100)->nullable();
            $table->integer('order')->default(0);
            $table->timestamps();
            
            $table->index(['report_id', 'order']);
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('report_entities');
    }
};
