<?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('orders', function (Blueprint $table): void {
            $table->id();
            $table->foreignId('user_id')->constrained()->cascadeOnDelete();
            $table->string('plan_code', 40);
            $table->string('type', 20); // one_time | subscription
            $table->string('currency', 10);
            $table->unsignedInteger('amount');
            $table->string('status', 20)->default('pending');
            $table->string('provider', 20)->nullable();
            $table->string('provider_ref', 100)->nullable();
            $table->timestamps();

            $table->index(['user_id', 'status']);
            $table->index(['provider', 'provider_ref']);
        });
    }

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