<?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
    {
        if (Schema::hasTable('shipping_fees')) return;
        
        Schema::create('shipping_fees', function (Blueprint $table) {
            $table->id();
            $table->string('country');
            $table->string('city')->nullable();
            $table->string('district')->nullable(); // Quartier/Commune
            $table->decimal('fee', 10, 2)->default(0);
            $table->decimal('free_shipping_minimum', 10, 2)->nullable(); // Livraison gratuite si commande >= montant
            $table->integer('estimated_days')->nullable(); // Délai de livraison estimé en jours
            $table->boolean('is_active')->default(true);
            $table->timestamps();
            
            // Index pour optimiser les recherches
            $table->index(['country', 'city', 'district']);
            $table->index('is_active');
        });
    }

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

