<?php

use App\Constants\Status;
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('plan_purchases', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('plan_id');
            $table->decimal('price', 28, 8)->default(0.00000000);
            $table->foreign('plan_id')->references('id')->on('plans')->onDelete('cascade');
            $table->json('extra')->nullable();
            $table->string('trx')->nullable();
            $table->foreignId('user_id')->constrained()->onDelete('cascade');
            $table->unsignedInteger('status')->default(Status::Pending);
            $table->timestamps();
        });
    }

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