<?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::table('users', function (Blueprint $table) {
            // Role: super_admin, admin_mapel, guru_mapel
            $table->string('role')->default('guru_mapel')->after('email'); 
            
            // Relasi ke tabel subjects (Boleh null jika Super Admin)
            $table->foreignId('subject_id')->nullable()->after('role')->constrained('subjects')->onDelete('set null');
        });
    }

    public function down(): void
    {
        Schema::table('users', function (Blueprint $table) {
            $table->dropForeign(['subject_id']);
            $table->dropColumn(['role', 'subject_id']);
        });
    }
};