<?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_imports', function (Blueprint $table) {
            $table
                ->bigInteger('mony_type_id')
                ->unsigned()
                
                ->after('id');
            $table
                ->bigInteger('customer_id')
                ->unsigned()
                ->nullable()
                ->after('mony_type_id');
            $table
                ->bigInteger('supplier_id')
                ->unsigned()
                ->nullable()
                ->after('customer_id');
            $table->date('date')->after('supplier_id');
            $table->double('value')->after('date');
            $table
                ->text('notes')
                ->nullable()
                ->after('value');
            $table
                ->foreign('mony_type_id')
                ->references('id')
                ->on('mony_types')
                ->onDelete('cascade')
                ->onUpdate('cascade');
            $table
                ->foreign('customer_id')
                ->references('id')
                ->on('customers')
                ->onDelete('cascade')
                ->onUpdate('cascade');
            $table
                ->foreign('supplier_id')
                ->references('id')
                ->on('suppliers')
                ->onDelete('cascade')
                ->onUpdate('cascade');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('mony_imports', function (Blueprint $table) {
            $table->dropColumn('mony_type_id');
            $table->dropColumn('customer_id');
            $table->dropColumn('supplier_id');
            $table->dropColumn('date');
            $table->dropColumn('value');
            $table->dropColumn('notes');
            $table->dropForeign('mony_imports_mony_type_id_foreign');
            $table->dropForeign('mony_imports_customer_id_foreign');
            $table->dropForeign('mony_imports_supplier_id_foreign');
        });
    }
};
