<?php

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

class AddDismissedStatusToDeductions extends Migration
{
    public function up()
    {
        DB::statement("ALTER TABLE salary_deductions MODIFY COLUMN status ENUM('pending', 'applied', 'cancelled', 'rejected', 'pending_dismissal', 'completed', 'dismissed') NOT NULL DEFAULT 'pending'");
        
        //employee dismissal fields
        Schema::table('salary_employees', function (Blueprint $table) {
            if (!Schema::hasColumn('salary_employees', 'dismissal_id')) {
                $table->unsignedBigInteger('dismissal_id')->nullable();
            }
            if (!Schema::hasColumn('salary_employees', 'dismissal_date')) {
                $table->date('dismissal_date')->nullable();
            }
            if (!Schema::hasColumn('salary_employees', 'dismissal_reason')) {
                $table->text('dismissal_reason')->nullable();
            }
        });
    }

    public function down()
    {
        DB::statement("ALTER TABLE salary_deductions MODIFY COLUMN status ENUM('pending', 'applied', 'cancelled', 'rejected', 'pending_dismissal', 'completed') NOT NULL DEFAULT 'pending'");
        
        Schema::table('salary_employees', function (Blueprint $table) {
            $table->dropColumn(['dismissal_id', 'dismissal_date', 'dismissal_reason']);
        });
    }
}