<?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('featured_payments', function (Blueprint $table) {
            $table->id();

            $table->string('payment_number'); // Format: FEA-YYYYMMDD-XXXX

            $table->unsignedBigInteger('user_id');
            $table->unsignedBigInteger('listing_id');
            $table->unsignedBigInteger('payment_id')->nullable();

            $table->decimal('amount', 10, 2);
            $table->string('currency')->default('USD');

            $table->enum('payment_method', ['card', 'paypal', 'bank_transfer', 'wallet'])->nullable();

            $table->enum('status', ['pending', 'completed', 'failed', 'refunded'])
                  ->default('pending');

            $table->timestamp('featured_start_at');
            $table->timestamp('featured_end_at');

            $table->integer('duration_days');

            $table->string('transaction_id')->nullable();
            $table->timestamp('paid_at')->nullable();

            $table->string('receipt_url')->nullable();

            $table->decimal('refunded_amount', 10, 2)->default(0.00);
            $table->timestamp('refunded_at')->nullable();
            $table->text('refund_reason')->nullable();

            $table->string('stripe_payment_intent_id')->nullable();
            $table->string('stripe_charge_id')->nullable();

            $table->longText('metadata')->nullable();

            $table->timestamps();

            // Indexes
            $table->index('payment_number');
            $table->index('user_id');
            $table->index('listing_id');
            $table->index('payment_id');
            $table->index('status');
        });
    }

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