<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::table('users', function (Blueprint $table) {
            if (! Schema::hasColumn('users', 'phone')) {
                $table->string('phone')->nullable()->after('email');
            }
            if (! Schema::hasColumn('users', 'gender')) {
                $table->enum('gender', ['male', 'female', 'other', 'notsay'])->nullable()->after('phone');
            }
            if (! Schema::hasColumn('users', 'date_of_birth')) {
                $table->date('date_of_birth')->nullable()->after('gender');
            }
            if (! Schema::hasColumn('users', 'address')) {
                $table->text('address')->nullable()->after('date_of_birth');
            }
            if (! Schema::hasColumn('users', 'country')) {
                $table->string('country')->nullable()->after('address');
            }
            if (! Schema::hasColumn('users', 'state')) {
                $table->string('state')->nullable()->after('country');
            }
            if (! Schema::hasColumn('users', 'city')) {
                $table->string('city')->nullable()->after('state');
            }
            if (! Schema::hasColumn('users', 'zip')) {
                $table->string('zip')->nullable()->after('city');
            }
            if (! Schema::hasColumn('users', 'avatar')) {
                $table->string('avatar')->nullable()->after('zip');
            }
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('users', function (Blueprint $table) {
            $table->dropColumn([
                'phone',
                'gender',
                'date_of_birth',
                'address',
                'country',
                'state',
                'city',
                'zip',
                'avatar',
            ]);
        });
    }
};
