<?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('sales', function (Blueprint $table) {
            $table
                ->bigInteger('customer_id')
                ->unsigned()
                ->nullable()
                ->after('id');
            $table
                ->bigInteger('supplier_id')
                ->unsigned()
                ->nullable()
                ->after('customer_id');
            $table
                ->double('tot')
                ->nullable()
                ->after('supplier_id');
            $table->date('date')->after('tot');
            $table
                ->text('notes')
                ->nullable()
                ->after('date');
            $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('sales', function (Blueprint $table) {
            $table->dropColumn('customer_id');
            $table->dropColumn('supplier_id');
            $table->dropColumn('tot');
            $table->dropColumn('date');
            $table->dropColumn('notes');
            $table->dropForeign('sales_customer_id_foreign');
            $table->dropForeign('sales_supplier_id_foreign');
        });
    }
};
