<?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
    {
        Schema::create('siswa_badges', function (Blueprint $table) {
            $table->id('id_siswa_badge');
            $table->string('nisn', 20);
            $table->unsignedBigInteger('id_badge');
            $table->timestamp('tanggal_diberikan')->useCurrent();
            $table->timestamps();

            $table->foreign('nisn')
                  ->references('nisn')
                  ->on('siswas')
                  ->onDelete('cascade');
            
            $table->foreign('id_badge')
                  ->references('id_badge')
                  ->on('badges')
                  ->onDelete('cascade');
        });
    }

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