<?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('challenges', function (Blueprint $table) {
            $table->id('id_challenge');
            $table->unsignedBigInteger('id_admin');
            $table->string('judul_challenge', 200);
            $table->text('deskripsi')->nullable();
            $table->integer('exp')->default(0);
            $table->unsignedBigInteger('id_badge')->nullable();
            $table->datetime('tenggat_waktu');
            $table->timestamps();

            $table->foreign('id_admin')
                  ->references('id_admin')
                  ->on('admins')
                  ->onDelete('cascade');
            
            $table->foreign('id_badge')
                  ->references('id_badge')
                  ->on('badges')
                  ->onDelete('set null');
        });
    }

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