<?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('finance_invoices', function (Blueprint $table) {
            $table->foreignId('recurring_invoice_id')->nullable()->after('client_id')->constrained('finance_recurring_invoices')->onDelete('set null');
            $table->string('public_hash')->nullable()->unique()->after('status');
        });
    }

    public function down(): void
    {
        Schema::table('finance_invoices', function (Blueprint $table) {
            $table->dropForeign(['recurring_invoice_id']);
            $table->dropColumn(['recurring_invoice_id', 'public_hash']);
        });
    }
};
