<?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('leaderboards', function (Blueprint $table) {
            $table->id('id_history');
            $table->string('nisn', 20);
            $table->string('id_kelas', 20);
            $table->integer('total_exp')->default(0);
            $table->integer('ranking');
            $table->string('semester', 50);
            $table->string('tahun_ajaran', 20);
            $table->timestamp('tanggal_snapshot')->useCurrent();
            $table->timestamps();

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

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