<?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('company_employees', function (Blueprint $table) {
            // Encrypted NIN storage (AES-GCM components)
            $table->text('nin_encrypted')->nullable()->after('email'); // Ciphertext
            $table->string('nin_iv', 64)->nullable()->after('nin_encrypted'); // Initialization Vector
            $table->string('nin_tag', 64)->nullable()->after('nin_iv'); // Authentication Tag

            $table->boolean('is_nin_verified')->default(false)->after('nin_tag');
            $table->string('nin_verification_token', 64)->nullable()->unique()->after('is_nin_verified');
            $table->timestamp('nin_verified_at')->nullable()->after('nin_verification_token');

            $table->index('is_nin_verified');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('company_employees', function (Blueprint $table) {
            $table->dropIndex(['is_nin_verified']);
            $table->dropColumn([
                'nin_encrypted',
                'nin_iv',
                'nin_tag',
                'is_nin_verified',
                'nin_verification_token',
                'nin_verified_at',
            ]);
        });
    }
};
