<?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_offset_earnings', function (Blueprint $table) {
            if(!Schema::hasColumn('employee_offset_earnings', 'validated')){
                $table->tinyInteger('validated')->default(0)->after('approved_at');
            }
            
            if(!Schema::hasColumn('employee_offset_earnings', 'validated_by')){
                $table->String('validated_by')->nullable()->after('validated');
            }

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

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

        });
    }

    /**
     * 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);
                }
            }
        });
    }

};
