<?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('orders', function (Blueprint $table) {
            $table->foreignId('livreur_id')->nullable()->after('user_id')->constrained('users')->nullOnDelete();
            $table->string('delivery_status', 32)->default('pending')->after('status');
            $table->timestamp('delivery_assigned_at')->nullable()->after('delivery_status');
            $table->timestamp('delivered_at')->nullable()->after('delivery_assigned_at');
            $table->string('delivery_proof_path')->nullable()->after('delivered_at');
        });
    }

    public function down(): void
    {
        Schema::table('orders', function (Blueprint $table) {
            $table->dropForeign(['livreur_id']);
            $table->dropColumn([
                'livreur_id',
                'delivery_status',
                'delivery_assigned_at',
                'delivered_at',
                'delivery_proof_path',
            ]);
        });
    }
};

