<?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('annonces', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained()->cascadeOnDelete();

            $table->string('type'); // marketplace, evenement, emploi, annuaire
            $table->string('titre');
            $table->text('description');
            $table->string('localisation')->nullable();

            // Contact affiché sur l'annonce
            $table->string('contact_nom')->nullable();
            $table->string('contact_telephone')->nullable();
            $table->string('contact_email')->nullable();

            // Workflow + paiement hors-ligne
            $table->string('statut')->default('brouillon');
            $table->decimal('frais', 10, 2)->default(0);            // frais de publication
            $table->string('paiement_reference')->nullable();       // réf. NatCash/MonCash
            $table->timestamp('paiement_confirme_le')->nullable();

            // Cycle de vie
            $table->timestamp('publiee_le')->nullable();
            $table->timestamp('expire_le')->nullable();

            // Compteurs simples (Phase 1)
            $table->unsignedInteger('vues')->default(0);
            $table->unsignedInteger('likes')->default(0);

            $table->timestamps();

            $table->index(['type', 'statut']); // recherches fréquentes par type + statut
        });
    }

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