<?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
    {
        Schema::create('struttura_fisica_dettaglio', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('stabile_id');
            $table->string('palazzina', 10); // A, B, C o 1, 2, 3
            $table->string('scala', 10)->nullable(); // 1, 2, 3 o A, B, C
            $table->integer('piano'); // -2, -1, 0, 1, 2, 3... (0=piano terra)
            $table->integer('numero_interni')->default(1);
            $table->boolean('presenza_ascensore')->default(false);
            $table->text('note')->nullable();
            $table->timestamps();
            
            // Foreign keys e indici
            $table->foreign('stabile_id')->references('id')->on('stabili')->onDelete('cascade');
            $table->index(['stabile_id', 'palazzina', 'scala', 'piano'], 'idx_stabile_struttura');
        });
    }

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