<?php

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

return new class extends Migration {
    public function up()
    {
        Schema::table('tasks', function (Blueprint $table) {
            if (!Schema::hasColumn('tasks', 'status_id')) {
                $table->unsignedBigInteger('status_id')->nullable()->after('type');
            }
            if (!Schema::hasColumn('tasks', 'needs_delivery')) {
                $table->boolean('needs_delivery')->default(false)->after('status_id');
            }
            if (!Schema::hasColumn('tasks', 'severity_id')) {
                $table->unsignedBigInteger('severity_id')->nullable()->after('needs_delivery');
            }
            if (!Schema::hasColumn('tasks', 'completed_at')) {
                $table->timestamp('completed_at')->nullable()->after('severity_id');
            }
            if (!Schema::hasColumn('tasks', 'labour')) {
                $table->decimal('labour', 8, 2)->default(0)->after('completed_at');
            }
        });
    }

    public function down()
    {
        Schema::table('tasks', function (Blueprint $table) {
            if (Schema::hasColumn('tasks', 'status_id')) {
                $table->dropColumn('status_id');
            }
            if (Schema::hasColumn('tasks', 'needs_delivery')) {
                $table->dropColumn('needs_delivery');
            }
            if (Schema::hasColumn('tasks', 'severity_id')) {
                $table->dropColumn('severity_id');
            }
            if (Schema::hasColumn('tasks', 'completed_at')) {
                $table->dropColumn('completed_at');
            }
            if (Schema::hasColumn('tasks', 'labour')) {
                $table->dropColumn('labour');
            }
        });
    }
}; 