<?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('tasks', function (Blueprint $table) {
            $table->boolean('needs_pickup')->default(false)->after('needs_delivery');
            $table->unsignedInteger('pickup_by')->nullable()->after('needs_pickup');
            $table->timestamp('pickup_schedule')->nullable()->after('pickup_by')->comment('Scheduled date/time for pickup');
            $table->timestamp('picked_up_at')->nullable()->after('pickup_schedule');

            // Add foreign key for pickup_by
            $table->foreign('pickup_by')->references('id')->on('users')->onDelete('set null');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('tasks', function (Blueprint $table) {
            $table->dropForeign(['pickup_by']);
            $table->dropColumn(['needs_pickup', 'pickup_by', 'pickup_schedule', 'picked_up_at']);
        });
    }
};
