<?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_offsets', function (Blueprint $table) {

            if(!Schema::hasColumn('employee_offsets', 'validated_at')){
                $table->timestamp('validated_at')->nullable()->after('validated_by');
            }

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

        });
    }

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

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