<?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('group_member', function (Blueprint $table) {
            $table->id();
            $table->foreignId('group_id')->constrained()->cascadeOnDelete();
            $table->foreignId('member_id')->constrained()->cascadeOnDelete();
            $table->string('role_in_group', 30)->nullable();
            $table->date('joined_at')->nullable();
            $table->timestamps();

            $table->unique(['group_id', 'member_id']);
        });
    }

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