<?php
declare(strict_types=1);

function log_system_activity(PDO $pdo, array $data): void
{
    $sql = "INSERT INTO system_activity_logs
    (user_id, employee_id, branch_id, module, action_type, entity_type, entity_id, title, description, url, icon, color, created_at)
    VALUES
    (:user_id, :employee_id, :branch_id, :module, :action_type, :entity_type, :entity_id, :title, :description, :url, :icon, :color, NOW())";

    $stmt = $pdo->prepare($sql);
    $stmt->execute([
        ':user_id'      => $data['user_id'] ?? null,
        ':employee_id'  => $data['employee_id'] ?? null,
        ':branch_id'    => $data['branch_id'] ?? null,
        ':module'       => $data['module'] ?? '',
        ':action_type'  => $data['action_type'] ?? '',
        ':entity_type'  => $data['entity_type'] ?? '',
        ':entity_id'    => $data['entity_id'] ?? null,
        ':title'        => $data['title'] ?? '',
        ':description'  => $data['description'] ?? null,
        ':url'          => $data['url'] ?? null,
        ':icon'         => $data['icon'] ?? 'history',
        ':color'        => $data['color'] ?? 'blue',
    ]);
}