<?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_company_group_preferences', function (Blueprint $table) {
            $table->id();
            $table->string('username', 50);
            $table->foreignId('company_group_id')->nullable()->constrained('company_groups')->cascadeOnDelete();
            $table->json('hidden_company_ids')->nullable();
            $table->timestamps();

            $table->unique(['username', 'company_group_id']);
        });
    }

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