<?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('leave_requests', function (Blueprint $row) {
            $row->id();
            $row->foreignId('user_id')->constrained()->onDelete('cascade');
            $row->foreignId('leave_type_id')->constrained()->onDelete('cascade');
            $row->date('start_date');
            $row->date('end_date');
            $row->decimal('total_days', 8, 2);
            $row->text('reason')->nullable();

            $row->enum('status', [
                'pending_manager',
                'pending_admin',
                'approved',
                'rejected_manager',
                'rejected_admin',
            ])->default('pending_manager');

            $row->foreignId('manager_id')->nullable()->constrained('users')->onDelete('set null');
            $row->timestamp('manager_approved_at')->nullable();
            $row->text('manager_comment')->nullable();

            $row->foreignId('admin_approved_by')->nullable()->constrained('users')->onDelete('set null');
            $row->timestamp('admin_approved_at')->nullable();
            $row->text('admin_comment')->nullable();

            $row->timestamps();
        });
    }

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