<?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('permissions', function (Blueprint $table) {
            $table->id();
            $table->enum('reason', ['sakit', 'izin', 'dispen', 'lainnya']);
            $table->text('information')->nullable(true);
            $table->string('evidence');
            $table->enum('status', ['proses', 'diterima', 'ditolak']);
            $table->string('feedback')->nullable(true); // feedback message from admin
            $table->date('date_permission'); // tanggal izin
            $table->integer('time_period'); // jumlah jam izin, misal 2 jam untuk 2 periode

            // relationship foreign key
            $table->foreignId('id_student')->constrained('students')->onDelete('cascade');

            // relation for approval by admin or teacher.
            $table->foreignId('approved_by')->nullable()->constrained('users')->nullOnDelete();

            // timestamp
            $table->timestamps();
        });
    }

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