<?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('internal_id')->nullable();
            $table->foreignId('customer_id')->nullable()->constrained();

            $table->string('status')->default('UNPAID');

            $table->decimal('subtotal', 8, 2)->default(0.00);
            $table->decimal('total', 8, 2)->default(0.00);

            $table->decimal('pst_rate', 8, 2);
            $table->decimal('gst_rate', 8, 2);
            $table->decimal('hst_rate', 8, 2);

            $table->decimal('pst_amount', 8, 2)->nullable();
            $table->decimal('gst_amount', 8, 2)->nullable();
            $table->decimal('hst_amount', 8, 2)->nullable();

            $table->boolean('has_pst')->default(false);
            $table->boolean('has_gst')->default(true);
            $table->boolean('has_hst')->default(false);

            $table->date('date')->default(today());
            $table->date('due_date')->nullable();

            $table->softDeletes();
            $table->timestamps();
        });
    }

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