<?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::create('invoices', function (Blueprint $table) {
            $table->id();
            $table->string('invoice_number')->unique();
            $table->string('order_id'); // String because 'orders.order_id' is string
            $table->string('customer_name');
            $table->string('customer_email');
            $table->text('billing_address');
            $table->date('invoice_date');
            
            $table->decimal('subtotal', 10, 2);
            $table->decimal('tax_percentage', 5, 2)->default(0); // e.g. 18.00
            $table->decimal('tax_amount', 10, 2)->default(0);
            $table->decimal('shipping_cost', 10, 2)->default(0);
            $table->decimal('discount_amount', 10, 2)->default(0);
            $table->decimal('total_amount', 10, 2);
            $table->string('status')->default('paid'); // paid, unpaid, cancelled
            
            $table->timestamps();

            // Foreign key logically links to 'orders', but orders.id is not used here (using order_id string)
            // Just indexing for speed
            $table->index('order_id');
        });
    }

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