<?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
    {
        if (!Schema::hasColumn('invoice_items', 'is_delivered')) {
            Schema::table('invoice_items', function (Blueprint $table) {
                $table->boolean('is_delivered')->default(false)->after('metadata');
                $table->timestamp('delivered_at')->nullable()->after('is_delivered');
                $table->foreignId('delivered_by')->nullable()->constrained('users')->after('delivered_at');
            });
        }
    }

    public function down(): void
    {
        Schema::table('invoice_items', function (Blueprint $table) {
            $table->dropColumn(['is_delivered', 'delivered_at', 'delivered_by']);
        });
    }
};
