<?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('prestasis', function (Blueprint $table) {
            $table->id();

            $table->unsignedBigInteger('user_id');
            $table->unsignedBigInteger('santri_id');
            $table->unsignedBigInteger('kelas_id');

            $table->string('jenis_prestasi');
            $table->string('nama_prestasi');
            $table->string('tingkat');
            $table->string('peringkat');
            $table->date('tanggal_prestasi');
            $table->text('deskripsi')->nullable();
            $table->string('sertifikat')->nullable();

            $table->timestamps();

            // Foreign keys
            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
            $table->foreign('santri_id')->references('id')->on('santris')->onDelete('cascade');
            $table->foreign('kelas_id')->references('id')->on('kelas')->onDelete('cascade');
        });
    }

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