<?php
defined( 'ABSPATH' ) || exit;

class NASEO_Logger {

    const OPTION = 'naseo_logs';
    const MAX    = 200;

    public static function log( string $type, string $message ): void {
        $logs   = get_option( self::OPTION, [] );
        $logs[] = [
            'time'    => current_time( 'mysql' ),
            'type'    => $type,
            'message' => $message,
        ];

        // Зберігаємо тільки останні 200
        if ( count( $logs ) > self::MAX ) {
            $logs = array_slice( $logs, -self::MAX );
        }

        update_option( self::OPTION, $logs );
    }

    public static function get( int $limit = 50 ): array {
        $logs = get_option( self::OPTION, [] );
        return array_reverse( array_slice( $logs, -$limit ) );
    }

    public static function clear(): void {
        update_option( self::OPTION, [] );
    }
}
