<?php

final class Audit
{
    public static function log(int $ticketId, ?int $userId, string $action, ?string $field = null,
                               ?string $old = null, ?string $new = null, ?string $note = null): void
    {
        DB::run(
            'INSERT INTO ticket_history (ticket_id, user_id, action, field_name, old_value, new_value, note)
             VALUES (?,?,?,?,?,?,?)',
            [$ticketId, $userId, $action, $field,
             $old === null ? null : mb_substr($old, 0, 255),
             $new === null ? null : mb_substr($new, 0, 255),
             $note === null ? null : mb_substr($note, 0, 500)]
        );
    }
}
