<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddMissingColumnsToEmployeeDismissals extends Migration
{
    public function up()
    {
        Schema::table('employee_dismissals', function (Blueprint $table) {
            // Add missing columns
            if (!Schema::hasColumn('employee_dismissals', 'reason')) {
                $table->text('reason')->nullable()->after('dismissal_reason');
            }
            
            if (!Schema::hasColumn('employee_dismissals', 'comments')) {
                $table->text('comments')->nullable()->after('hr_notes');
            }
            
            if (!Schema::hasColumn('employee_dismissals', 'requires_settlement')) {
                $table->boolean('requires_settlement')->default(false)->after('settlement_paid_at');
            }
            
            if (!Schema::hasColumn('employee_dismissals', 'completion_comments')) {
                $table->text('completion_comments')->nullable()->after('clearance_notes');
            }
            
            if (!Schema::hasColumn('employee_dismissals', 'completed_by')) {
                $table->unsignedBigInteger('completed_by')->nullable()->after('processed_by');
            }
            
            if (!Schema::hasColumn('employee_dismissals', 'completed_at')) {
                $table->timestamp('completed_at')->nullable()->after('processed_at');
            }
        });
    }
    
    public function down()
    {
        Schema::table('employee_dismissals', function (Blueprint $table) {
            $table->dropColumn([
                'reason',
                'comments',
                'requires_settlement',
                'completion_comments',
                'completed_by',
                'completed_at'
            ]);
        });
    }
}