<?php
class DownloadTracker {
    public static function log($pdf_id, $recipient_id, $ip) {
        global $db;

        $sql = "
            INSERT INTO pdf_download_stats (pdf_id, recipient_id, ip_address)
            VALUES (?, ?, ?)
        ";

        try {
            $stmt = $db->prepare($sql);
            $params = [$pdf_id, $recipient_id, $ip];
            $stmt->execute($params);
            ErrorLogger::logSqlSuccess('download_tracker: insert download stat | SQL: ' . $sql . ' | params: ' . json_encode($params, JSON_UNESCAPED_UNICODE));
        } catch (Throwable $e) {
            ErrorLogger::logSqlError('download_tracker: insert download stat failed | SQL: ' . $sql . ' | params: ' . json_encode([$pdf_id, $recipient_id, $ip], JSON_UNESCAPED_UNICODE) . ' | error: ' . $e->getMessage());
        }
    }
}
