<?php

namespace FleekDash\Integrations\Core;

defined('ABSPATH') || exit;

/**
 * Persists webhook audit entries (delivery, failure, received).
 */
final class WebhookLogRepository
{
    private const OPTION_LOGS = 'fleekdash_webhook_logs';

    private const MAX_LOG_ENTRIES = 1000;

    public static function append(array $log): void
    {
        $logs = get_option(self::OPTION_LOGS, []);
        if (!is_array($logs)) {
            $logs = [];
        }
        $logs[] = $log;
        if (count($logs) > self::MAX_LOG_ENTRIES) {
            $logs = array_slice($logs, -self::MAX_LOG_ENTRIES);
        }
        update_option(self::OPTION_LOGS, $logs);
    }
}
