<?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::table('attendances', function (Blueprint $table) {
            $table->enum('anomaly_status', [
                'pending_manager',
                'approved_manager',
                'rejected_manager',
                'pending_admin',
                'approved_admin',
                'rejected_admin',
            ])->nullable()->after('status');

            $table->foreignId('manager_approved_by')->nullable()->constrained('users')->after('anomaly_status');
            $table->timestamp('manager_approved_at')->nullable()->after('manager_approved_by');

            $table->foreignId('admin_approved_by')->nullable()->constrained('users')->after('manager_approved_at');
            $table->timestamp('admin_approved_at')->nullable()->after('admin_approved_by');

            $table->text('anomaly_reason')->nullable()->after('admin_approved_at');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('attendances', function (Blueprint $table) {
            $table->dropForeign(['manager_approved_by']);
            $table->dropForeign(['admin_approved_by']);
            $table->dropColumn([
                'anomaly_status',
                'manager_approved_by',
                'manager_approved_at',
                'admin_approved_by',
                'admin_approved_at',
                'anomaly_reason',
            ]);
        });
    }
};
