<?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_columns', function (Blueprint $table) {
            $table->id();
            $table->foreignId('report_id')->constrained()->cascadeOnDelete();
            $table->string('key', 100);
            $table->string('label');
            $table->string('type', 50)->default('string');
            $table->text('expression');
            $table->boolean('sortable')->default(true);
            $table->boolean('visible')->default(true);
            $table->integer('order')->default(0);
            $table->json('format_options')->nullable();
            $table->timestamps();
            
            $table->index(['report_id', 'order']);
        });
    }

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