<?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::table('records', function (Blueprint $table) {
            $table->date('data_pagamento')->nullable()->after('date');
            $table->string('numero_fattura')->nullable();
            $table->string('tipo_documento')->nullable()->after('type');
            $table->string('BIC')->nullable()->after('tipo_documento');
            $table->string('IBAN')->nullable()->after('BIC');
            $table->date('data_scadenza')->nullable()->after('IBAN');
            $table->unsignedBigInteger('bank_id')->nullable()->after('data_scadenza');
            $table->string('condizioni_pagamento')->nullable()->after('bank_id');
            $table->boolean('is_ricevuta')->default(false);
            $table->foreign('bank_id')
                  ->references('id')
                  ->on('banks')
                  ->onDelete('set null')
                  ->onUpdate('cascade');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('records', function (Blueprint $table) {
            $table->dropForeign(['bank_id']);

            $table->dropColumn([
                'data_documento',
                'numero_fattura',
                'tipo_documento',
                'BIC',
                'IBAN',
                'data_scadenza',
                'bank_id',
                'condizioni_pagamento'
            ]);
        });
    }
};
