<?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('subscriptions', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained()->onDelete('cascade');
            $table->string('plan');                    // free | pro | enterprise
            $table->string('status');                  // active | expired | cancelled | pending
            $table->string('midtrans_order_id')->nullable()->unique();
            $table->string('midtrans_transaction_id')->nullable();
            $table->string('payment_method')->nullable();  // bank_transfer, gopay, dana, dll
            $table->string('payment_channel')->nullable(); // BCA, BRI, BNI, dll
            $table->decimal('amount', 12, 0)->default(0);
            $table->timestamp('started_at')->nullable();
            $table->timestamp('expired_at')->nullable();
            $table->json('midtrans_payload')->nullable();   // simpan raw response
            $table->timestamps();
        });
    }

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