<?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
    {
        // Grup pengguna: admin (1), members (2), developer (3) — lihat RPD §6.
        Schema::create('groups', function (Blueprint $table) {
            $table->id();
            $table->string('name', 40)->unique();
            $table->string('description')->nullable();
            $table->timestamps();
        });

        // Relasi user–grup (banyak-ke-banyak). Seorang user bisa tergabung >1 grup.
        Schema::create('users_groups', function (Blueprint $table) {
            $table->foreignId('user_id')->constrained()->cascadeOnDelete();
            $table->foreignId('group_id')->constrained('groups')->cascadeOnDelete();
            $table->primary(['user_id', 'group_id']);
        });
    }

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