<?php

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

return new class extends Migration {
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('mony_exports', function (Blueprint $table) {
            $table
                ->bigInteger('employee_id')
                ->unsigned()
                ->nullable()
                ->after('notes');
            $table
                ->bigInteger('equip_id')
                ->unsigned()
                ->nullable()
                ->after('employee_id');
            $table
                ->bigInteger('land_id')
                ->unsigned()
                ->nullable()
                ->index()
                ->change();
            $table
                ->bigInteger('customer_id')
                ->unsigned()
                ->nullable()
                ->index()
                ->change();
            $table
                ->bigInteger('supplier_id')
                ->unsigned()
                ->nullable()
                ->index()
                ->change();
            $table
                ->foreign('employee_id')
                ->references('id')
                ->on('employees')
                ->onDelete('cascade')
                ->onUpdate('cascade');
            $table
                ->foreign('equip_id')
                ->references('id')
                ->on('equips')
                ->onDelete('cascade')
                ->onUpdate('cascade');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('mony_exports', function (Blueprint $table) {
            $table->dropColumn('employee_id');
            $table->dropColumn('equip_id');
            $table
                ->bigInteger('land_id')
                ->unsigned()
                ->index()
                ->change();
            $table
                ->bigInteger('customer_id')
                ->unsigned()
                ->index()
                ->change();
            $table
                ->bigInteger('supplier_id')
                ->unsigned()
                ->index()
                ->change();
            $table->dropForeign('mony_exports_employee_id_foreign');
            $table->dropForeign('mony_exports_equip_id_foreign');
        });
    }
};
