<?php

declare(strict_types=1);

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::create('invoice_lines', function (Blueprint $table): void {
            $table->id();
            $table->foreignId('invoice_id')->constrained('invoices')->cascadeOnDelete();
            $table->unsignedInteger('sort_order')->default(0);
            $table->unsignedBigInteger('item_id')->nullable()->index();
            $table->text('description');
            $table->decimal('quantity', 15, 4)->default(1);
            $table->decimal('unit_price_ex_vat', 15, 4);
            $table->foreignId('vat_rate_id')->constrained('maestro_vat_rates')->restrictOnDelete();
            $table->decimal('line_total_ex_vat', 15, 2);
            $table->decimal('line_vat_amount', 15, 2);
            $table->decimal('line_total_inc_vat', 15, 2);
            $table->timestamps();
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('invoice_lines');
    }
};
