<?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('recruitment_report_saved_filters', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('tenant_id')->index();
            $table->foreignId('user_id')->constrained('users')->cascadeOnDelete();
            $table->string('name', 120);
            $table->string('report_type', 64);
            $table->json('filters');
            $table->boolean('is_default')->default(false);
            $table->timestamps();

            $table->unique(['tenant_id', 'user_id', 'name'], 'rrsf_tenant_user_name_uq');
            $table->index(['tenant_id', 'user_id', 'report_type'], 'rrsf_tenant_user_type_idx');
        });
    }

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