<?php
require 'vendor/autoload.php';
$app = require_once 'bootstrap/app.php';
$app->make('Illuminate\Contracts\Console\Kernel')->bootstrap();

use App\Models\ShippingFee;

echo "=== STATISTIQUES FINALES ===" . PHP_EOL;
echo "Total zones de livraison: " . ShippingFee::count() . PHP_EOL;
echo "Pays couverts: " . ShippingFee::distinct('country')->count('country') . PHP_EOL;
echo "Villes couvertes: " . ShippingFee::distinct('city')->count('city') . PHP_EOL;
echo "Quartiers uniques: " . ShippingFee::distinct('district')->count('district') . PHP_EOL;
echo PHP_EOL;

echo "=== QUARTIERS EN CÔTE D'IVOIRE ===" . PHP_EOL;
$ci = ShippingFee::where('country', "Côte d'Ivoire")
    ->selectRaw('city, COUNT(DISTINCT district) as nb_quartiers')
    ->groupBy('city')
    ->orderByDesc('nb_quartiers')
    ->limit(15)
    ->get();

foreach ($ci as $c) {
    echo $c->city . ": " . $c->nb_quartiers . " quartiers" . PHP_EOL;
}
echo PHP_EOL;

echo "=== QUARTIERS D'ABIDJAN ===" . PHP_EOL;
$abidjan = ShippingFee::where('country', "Côte d'Ivoire")
    ->where('city', 'Abidjan')
    ->orderBy('district')
    ->get();
echo "Total: " . $abidjan->count() . " quartiers" . PHP_EOL;
foreach ($abidjan->take(25) as $q) {
    echo "  - " . $q->district . " (" . $q->fee . " XOF)" . PHP_EOL;
}
if ($abidjan->count() > 25) {
    echo "  ... et " . ($abidjan->count() - 25) . " autres" . PHP_EOL;
}
echo PHP_EOL;

echo "=== QUARTIERS DE DAKAR ===" . PHP_EOL;
$dakar = ShippingFee::where('country', "Sénégal")
    ->where('city', 'Dakar')
    ->orderBy('district')
    ->get();
echo "Total: " . $dakar->count() . " quartiers" . PHP_EOL;
foreach ($dakar->take(15) as $q) {
    echo "  - " . $q->district . " (" . $q->fee . " XOF)" . PHP_EOL;
}

echo PHP_EOL;
echo "=== QUARTIERS DE DOUALA ===" . PHP_EOL;
$douala = ShippingFee::where('country', "Cameroun")
    ->where('city', 'Douala')
    ->orderBy('district')
    ->get();
echo "Total: " . $douala->count() . " quartiers" . PHP_EOL;
foreach ($douala->take(15) as $q) {
    echo "  - " . $q->district . " (" . $q->fee . " XOF)" . PHP_EOL;
}
