<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('users', function (Blueprint $table) {
            if (!Schema::hasColumn('users', 'api_key')) {
                $table->string('api_key', 255)->nullable()->after('password');
            }
            if (!Schema::hasColumn('users', 'default_sender_id')) {
                $table->integer('default_sender_id')->nullable()->after('api_key');
            }
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('users', function (Blueprint $table) {
            if (Schema::hasColumn('users', 'api_key')) {
                $table->dropColumn('api_key');
            }
            if (Schema::hasColumn('users', 'default_sender_id')) {
                $table->dropColumn('default_sender_id');
            }
        });
    }
};
