<?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('paiements', function (Blueprint $table) {
            $table->id();
            $table->string('reference', 30)->unique()->notNull();
            $table->morphs('payeur');
            $table->enum('type_paiement', ['forfait_dossier', 'service_client', 'remuneration_candidat', 'caution', 'autre'])->notNull();
            $table->foreignId('forfait_id')->nullable()->constrained('forfaits')->nullOnDelete();
            $table->foreignId('mission_id')->nullable()->constrained('missions')->nullOnDelete();
            $table->decimal('montant', 10, 2)->notNull();
            $table->enum('moyen_paiement', ['especes', 'mobile_money_orange', 'mobile_money_mtn', 'virement', 'carte_bancaire'])->notNull();
            $table->string('numero_transaction_externe', 100)->nullable();
            $table->enum('statut', ['en_attente', 'confirme', 'echec', 'rembourse'])->default('en_attente');
            $table->foreignId('recu_par')->nullable()->constrained('users')->nullOnDelete();
            $table->text('notes')->nullable();
            $table->timestamp('paid_at')->nullable();
            $table->timestamps();
        });
    }

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