<?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('employee_overtimes', function (Blueprint $table) {
            if(!Schema::hasColumn('employee_undertimes', 'validated_at')){
                $table->timestamp('validated_at')->nullable()->after('validated_by');
            }

            if(!Schema::hasColumn('employee_overtimes', 'deferred_reason')){
                $table->text('deferred_reason')->nullable()->after('validated');
            }

        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('employee_overtimes', function (Blueprint $table){
            $columns = [
                'deferred_reason',
                'validated_at',
            ];

            foreach ($columns as $column) {
                if (Schema::hasColumn('employee_overtimes', $column)) {
                    $table->dropColumn($column);
                }
            }
        });
    }
};
