<?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::table('stabili', function (Blueprint $table) {
            // Campi bancari
            $table->string('iban_principale')->nullable()->after('note');
            $table->string('banca_principale')->nullable()->after('iban_principale');
            $table->string('filiale')->nullable()->after('banca_principale');
            $table->string('iban_secondario')->nullable()->after('filiale');
            $table->string('banca_secondaria')->nullable()->after('iban_secondario');
            $table->string('filiale_secondaria')->nullable()->after('banca_secondaria');
            
            // Dati amministratore semplificati
            $table->string('amministratore_nome')->nullable()->after('filiale_secondaria');
            $table->string('amministratore_email')->nullable()->after('amministratore_nome');
            $table->date('data_nomina')->nullable()->after('amministratore_email');
            $table->date('scadenza_mandato')->nullable()->after('data_nomina');
            
            // Dati catastali aggiuntivi
            $table->string('foglio')->nullable()->after('scadenza_mandato');
            $table->string('mappale')->nullable()->after('foglio');
            $table->string('subalterno')->nullable()->after('mappale');
            $table->string('categoria')->nullable()->after('subalterno');
            $table->decimal('rendita_catastale', 10, 2)->nullable()->after('categoria');
            $table->decimal('superficie_catastale', 10, 2)->nullable()->after('rendita_catastale');
            
            // JSON per gestione palazzine multiple
            $table->json('palazzine_data')->nullable()->after('superficie_catastale');
            $table->json('locali_servizio')->nullable()->after('palazzine_data');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('stabili', function (Blueprint $table) {
            $table->dropColumn([
                'iban_principale',
                'banca_principale', 
                'filiale',
                'iban_secondario',
                'banca_secondaria',
                'filiale_secondaria',
                'amministratore_nome',
                'amministratore_email',
                'data_nomina',
                'scadenza_mandato',
                'foglio',
                'mappale',
                'subalterno',
                'categoria',
                'rendita_catastale',
                'superficie_catastale',
                'palazzine_data',
                'locali_servizio'
            ]);
        });
    }
};
