<?php

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

class AddProductFieldsToInvoices extends Migration
{
    public function up()
    {
        Schema::table('invoices', function (Blueprint $table) {
            // Fields to be added
            $table->bigIncrements('id');
            $table->string('prefix')->nullable()->comment("invoice number prefix");
            $table->text('invoice_owner_id')->nullable(); // Select the name of the user to whom the invoice is assigned.
            $table->text('customer_id')->nullable();
            $table->text('currency_id')->nullable();
            $table->text('status')->nullable();
            // Products related fields
            $table->text('selected_products')->nullable()->comment('store as json');
            $table->enum('discount_type_selected',['before', 'after'])->default('before');
            $table->string('discount_value')->nullable()->comment('discount_value');
            $table->string('total_tax')->nullable();
        });
    }
    public function down()
    {
        Schema::table('invoices', function (Blueprint $table) {
            $table->dropColumn('id');
            $table->dropColumn('prefix');
            $table->dropColumn('invoice_owner_id');
            $table->dropColumn('customer_id');
            $table->dropColumn('currency_id');
            $table->dropColumn('status');
            $table->dropColumn('selected_products');
            $table->dropColumn('discount_type_selected');
            $table->dropColumn('discount_value');
            $table->dropColumn('total_tax');
        });
    }
}
