<?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) {
            //
            $table->string('phone')->nullable()->after('email');

            $table->boolean('status')
                  ->default(true)
                  ->after('password');

            $table->foreignId('border_station_id')
                  ->nullable()
                  ->after('status')
                  ->constrained('border_stations')
                  ->nullOnDelete();

            $table->foreignId('created_by')
                  ->nullable()
                  ->after('border_station_id')
                  ->constrained('users')
                  ->nullOnDelete();

            $table->foreignId('updated_by')
                  ->nullable()
                  ->after('created_by')
                  ->constrained('users')
                  ->nullOnDelete();

        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('users', function (Blueprint $table) {
            //

            $table->dropForeign(['border_station_id']);
            $table->dropForeign(['created_by']);
            $table->dropForeign(['updated_by']);

            $table->dropColumn([
                'phone',
                'status',
                'border_station_id',
                'created_by',
                'updated_by',
            ]);

        });
    }
};
