<?php

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

class AlterPostulationsAddPropertyNullableAmount extends Migration
{
    public function up()
    {
        Schema::table('postulations', function (Blueprint $table) {
            $table->unsignedBigInteger('property_id')->nullable()->after('category_id');
            $table->json('photos')->nullable()->after('details');
            $table->float('amount')->nullable()->change();

            $table->foreign('property_id')->references('id')->on('properties')->onDelete('set null');
        });
    }

    public function down()
    {
        Schema::table('postulations', function (Blueprint $table) {
            $table->dropForeign(['property_id']);
            $table->dropColumn(['property_id', 'photos']);
            $table->float('amount')->nullable(false)->change();
        });
    }
}
