<?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('attendances', function (Blueprint $table) {
            // ID user yang melakukan scan QR (admin/HR)
            // NULL jika check-in/check-out mandiri
            $table->foreignId('scanned_by')->nullable()->after('check_out_app_version')
                ->constrained('users')->nullOnDelete();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('attendances', function (Blueprint $table) {
            $table->dropForeign(['scanned_by']);
            $table->dropColumn('scanned_by');
        });
    }
};
