<?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_monthly_schedules', function (Blueprint $table) {
            if(!Schema::hasColumn('employee_monthly_schedules', 'validated_by')){
                $table->string('validated_by',20)->nullable()->after('approved_at');
                
            }

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

            if(!Schema::hasColumn('employee_monthly_schedules', 'validated')){
                $table->integer('validated')->default(0)->after('validated_at');
            }

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

        });
    }

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

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