<?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('peserta_challenges', function (Blueprint $table) {
            $table->id('id_peserta');
            $table->unsignedBigInteger('id_challenge');
            $table->string('nisn', 20);
            $table->text('jawaban')->nullable();
            $table->datetime('waktu_submit')->nullable();
            $table->integer('exp')->default(0);
            $table->enum('status', ['selesai', 'belum'])->default('belum');
            $table->timestamps();

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

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