<?php

use App\Support\NigeriaStates;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('state_maps', function (Blueprint $table) {
            $table->id();
            $table->string('name')->unique();
            $table->string('slug')->unique();
            $table->string('state_code', 10)->unique();
            $table->decimal('latitude', 10, 7);
            $table->decimal('longitude', 10, 7);
            $table->unsignedTinyInteger('zoom_level')->default(8);
            $table->string('traffic_level', 30)->default('medium')->index();
            $table->text('traffic_summary')->nullable();
            $table->timestamps();
        });

        $now = now();
        $states = array_map(static function (array $state) use ($now): array {
            return array_merge($state, ['created_at' => $now, 'updated_at' => $now]);
        }, NigeriaStates::withSlugs());

        DB::table('state_maps')->insert($states);
    }

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