<?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
    {
        // Invoice deposit credit (RPD §12.2). status: Pending | Lunas | Batal.
        Schema::create('billings', function (Blueprint $table) {
            $table->id();
            $table->string('no_invoice', 20)->unique();        // format DDMMYYYY + 4 digit urut (BR-02)
            $table->unsignedInteger('jumlah_credit');
            $table->unsignedInteger('rate');                    // tarif Rp per credit
            $table->unsignedBigInteger('total');                // jumlah_credit * rate
            $table->foreignId('bank_id')->nullable()->constrained()->nullOnDelete();
            $table->string('status', 20)->default('Pending');   // BR-04
            $table->string('payment_method', 30)->default('manual'); // manual | duitku
            $table->foreignId('user_id')->constrained()->cascadeOnDelete(); // iduser
            $table->timestamp('paid_at')->nullable();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('billings');
    }
};
