<?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('notifications', function (Blueprint $table) {
            // Ubah nama field hospital_id ke user_id dan izinkan nilai null
            $table->renameColumn('hospital_id', 'user_id')->nullable();

            // Tambahkan field email setelah user_id
            $table->string('email')->after('hospital_id')->nullable();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('notifications', function (Blueprint $table) {
            // Rollback migrasi dengan mengembalikan nama field ke semula
            $table->renameColumn('user_id', 'hospital_id');

            // Hapus field email
            $table->dropColumn('email');
        });
    }
};
