<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('comuni_italiani', function (Blueprint $table) {
            $table->id();
            $table->string('codice_istat', 10)->unique();
            $table->string('denominazione');
            $table->string('denominazione_straniera')->nullable();
            $table->string('codice_catastale', 4)->nullable();
            $table->string('cap', 5)->nullable();
            $table->string('provincia_codice', 3)->nullable();
            $table->string('provincia_denominazione')->nullable();
            $table->string('regione_codice', 2)->nullable();
            $table->string('regione_denominazione')->nullable();
            $table->timestamps();

            // Indici per ottimizzare le ricerche
            $table->index('denominazione');
            $table->index('provincia_codice');
            $table->index('regione_codice');
            $table->index('cap');
        });
    }

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