<?php

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

class AddMissingColumnsToUsersTable extends Migration
{
    public function up()
    {
        Schema::table('users', function (Blueprint $table) {
            if (!Schema::hasColumn('users', 'desig')) {
                $table->integer('desig')->nullable()->after('role_id');
            }
            if (!Schema::hasColumn('users', 'refer')) {
                $table->integer('refer')->nullable()->after('desig');
            }
            if (!Schema::hasColumn('users', 'phone')) {
                $table->string('phone')->nullable()->after('email');
            }
            if (!Schema::hasColumn('users', 'is_approved')) {
                $table->boolean('is_approved')->default(false)->after('phone');
            }
            if (!Schema::hasColumn('users', 'joining_date')) {
                $table->date('joining_date')->nullable()->after('is_approved');
            }
            if (!Schema::hasColumn('users', 'joining_month')) {
                $table->string('joining_month')->nullable()->after('joining_date');
            }
            if (!Schema::hasColumn('users', 'joining_year')) {
                $table->integer('joining_year')->nullable()->after('joining_month');
            }
            if (!Schema::hasColumn('users', 'email_verified_at')) {
                $table->timestamp('email_verified_at')->nullable()->after('email');
            }
            if (!Schema::hasColumn('users', 'password')) {
                $table->string('password')->after('email_verified_at');
            }
            if (!Schema::hasColumn('users', 'remember_token')) {
                $table->string('remember_token', 100)->nullable()->after('password');
            }
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('users', function (Blueprint $table) {
            // if (Schema::hasColumn('users', 'desig')) {
            //     $table->dropColumn('desig');
            // }
            // if (Schema::hasColumn('users', 'phone')) {
            //     $table->dropColumn('phone');
            // }
            // if (Schema::hasColumn('users', 'is_approved')) {
            //     $table->dropColumn('is_approved');
            // }
            // if (Schema::hasColumn('users', 'joining_date')) {
            //     $table->dropColumn('joining_date');
            // }
            // if (Schema::hasColumn('users', 'joining_month')) {
            //     $table->dropColumn('joining_month');
            // }
            // if (Schema::hasColumn('users', 'joining_year')) {
            //     $table->dropColumn('joining_year');
            // }
            // if (Schema::hasColumn('users', 'email_verified_at')) {
            //     $table->dropColumn('email_verified_at');
            // }
            // if (Schema::hasColumn('users', 'password')) {
            //     $table->dropColumn('password');
            // }
            // if (Schema::hasColumn('users', 'remember_token')) {
            //     $table->dropColumn('remember_token');
            // }
        });
    }
}
