<?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->foreignId('user_id')->constrained()->onDelete('cascade');
            $table->foreignId('meter_reading_id')->unique()->constrained()->onDelete('cascade');
            $table->integer('pemakaian')->default(0);
            $table->string('invoice_number')->unique();
            $table->string('midtrans_order_id')->nullable()->unique();
            $table->decimal('total_amount', 10, 2);
            $table->date('due_date');
            $table->timestamp('paid_at')->nullable();
            $table->string('payment_method')->nullable();
            $table->string('transaction_id')->nullable();
            $table->string('payment_code')->nullable();
            $table->timestamp('published_at')->nullable();
            $table->string('status')->default('unpaid');
            $table->string('snap_token')->nullable();
            $table->timestamps();
        });
    }

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