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

            $table->string('provider'); // 'stripe', 'ach', etc.
            $table->string('payment_intent_id')->unique(); // Stripe PaymentIntent ID or ACH reference

            $table->unsignedBigInteger('company_id'); // The company making the payment
            $table->unsignedBigInteger('billing_request_id'); // The invoice being paid

            $table->unsignedBigInteger('amount'); // In cents. Always match gateway format.

            $table->string('status')->default('pending'); // pending | succeeded | failed | canceled

            $table->text('metadata')->nullable(); // Optional: JSON string for app-specific context

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

            $table->timestamps();
        });
    }

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