<?php
declare(strict_types=1);
namespace App\Services;

use App\Core\Database;

final class AuditService {
    public function log(string $module, string $action, ?int $recordId=null, array $payload=[]): void {
        $db = Database::instance();
        $userId = $_SESSION['uid'] ?? null;
        $stmt = $db->prepare("INSERT INTO audit_logs(user_id,module_name,action_name,record_id,payload_json,created_at) VALUES(?,?,?,?,?,NOW())");
        $stmt->execute([$userId, $module, $action, $recordId, json_encode($payload, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES)]);
    }
}
