<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::table('tasks', function (Blueprint $table) {
            $table->boolean('contractor_enabled')->default(false)->after('invoice_id');
            $table->foreignId('contractor_id')->nullable()->after('contractor_enabled')
                ->constrained('contractors')->nullOnDelete();
            $table->date('contractor_assigned_at')->nullable()->after('contractor_id');
            $table->decimal('contractor_wage', 15, 0)->nullable()->after('contractor_assigned_at');
            $table->decimal('customer_payment', 15, 0)->nullable()->after('contractor_wage');
            $table->decimal('contractor_profit', 15, 0)->nullable()->after('customer_payment');
        });
    }

    public function down(): void
    {
        Schema::table('tasks', function (Blueprint $table) {
            $table->dropConstrainedForeignId('contractor_id');
            $table->dropColumn([
                'contractor_enabled', 'contractor_assigned_at',
                'contractor_wage', 'customer_payment', 'contractor_profit',
            ]);
        });
    }
};
