<?php
declare(strict_types=1);

use App\Core\EventBus;
use App\Modules\Audit\Services\AuditService;

// Register database hooks for automatic audit logging
AuditService::registerDatabaseHooks();

// Listen for auth events
EventBus::listen('auth.login', function (array &$data) {
    AuditService::log(
        'login',
        'employee',
        $data['employee_id'] ?? null,
        null,
        null,
        null,
        'تسجيل دخول من IP: ' . ($data['ip'] ?? 'unknown')
    );
});

EventBus::listen('auth.logout', function (array &$data) {
    AuditService::log(
        'logout',
        'employee',
        $data['employee_id'] ?? null,
        null,
        null,
        null,
        'تسجيل خروج'
    );
});

EventBus::listen('auth.password_changed', function (array &$data) {
    AuditService::log(
        'update',
        'employee',
        $data['employee_id'] ?? null,
        null,
        null,
        null,
        'تم تغيير كلمة المرور'
    );
});