<?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('invoices', function (Blueprint $table) {
            $table->timestamp('delivered_at')->nullable()->after('paid_at');
            $table->foreignId('delivered_by')->nullable()->after('delivered_at')->constrained('users')->nullOnDelete();
            $table->string('delivery_recipient', 255)->nullable()->after('delivered_by');
            $table->text('delivery_note')->nullable()->after('delivery_recipient');
        });
    }

    public function down(): void
    {
        Schema::table('invoices', function (Blueprint $table) {
            $table->dropConstrainedForeignId('delivered_by');
            $table->dropColumn([
                'delivered_at',
                'delivery_recipient',
                'delivery_note',
            ]);
        });
    }
};
