<?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_conditions', function (Blueprint $table) {
            $table->id();
            $table->foreignId('report_id')->constrained()->cascadeOnDelete();
            $table->string('column');
            $table->string('operator', 50);
            $table->string('value_type', 50);
            $table->text('value')->nullable();
            $table->string('filter_key', 100)->nullable();
            $table->enum('logical_operator', ['AND', 'OR'])->default('AND');
            $table->integer('group_id')->nullable();
            $table->integer('order')->default(0);
            $table->boolean('enabled')->default(true);
            $table->timestamps();
            
            $table->index(['report_id', 'group_id', 'order']);
        });
    }

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