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

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('purchases', function (Blueprint $table) {
            $table->dropColumn('supplier_id');
            $table->dropColumn('customer_id');
            $table->dropColumn('tot_imp');
            $table->dropColumn('date');
            $table->dropColumn('notes');
            $table->dropForeign('purchases_supplier_id_foreign');
            $table->dropForeign('purchases_customer_id_foreign');
        });
    }
};
