<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Le montant payé est géré par la table paiements (liée à ventes).
     * On supprime la colonne redondante montant_paye de la table ventes.
     */
    public function up(): void
    {
        Schema::table('ventes', function (Blueprint $table) {
            if (Schema::hasColumn('ventes', 'montant_paye')) {
                $table->dropColumn('montant_paye');
            }
        });
    }

    public function down(): void
    {
        Schema::table('ventes', function (Blueprint $table) {
            if (! Schema::hasColumn('ventes', 'montant_paye')) {
                $table->decimal('montant_paye', 12, 0)->default(0)->after('statut_paiement');
            }
        });
    }
};
