<?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
    {
        Schema::create('subscription_invoices', function (Blueprint $table) {
            $table->id();
            $table->foreignId('store_id')->constrained('stores')->cascadeOnDelete();
            $table->foreignId('plan_id')->constrained('subscription_plans');
            $table->foreignId('referral_code_id')->nullable()->constrained('referral_codes');
            
            // Kolom krusial untuk follow-up jika ada masalah saldo
            $table->string('whatsapp_number'); 
            
            $table->decimal('total_amount', 15, 2); // Harga final setelah diskon
            $table->string('payment_proof')->nullable(); // Nama file struk
            $table->enum('status', ['pending', 'approved', 'rejected'])->default('pending');
            $table->timestamp('approved_at')->nullable();
            $table->timestamps();
        });
    }

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