<?php

namespace Openguru\OpenCartFramework\Support;

class WorkLogsBag
{
    private array $items;

    public function __construct(array $items = [])
    {
        $this->items = $items;
    }

    public function push(string $message): void
    {
        $this->items[] = sprintf('[%s] %s', date('Y-m-d H:i:s'), $message);
    }

    public function merge(array $items): void
    {
        $this->items = array_merge($this->items, $items);
    }

    public function getItems(): array
    {
        return $this->items;
    }

    public function formatAsList(): string
    {
        if (empty($this->items)) {
            return '';
        }

        $list = '<ul>';
        foreach ($this->items as $item) {
            $list .= sprintf('<li>%s</li>', $item);
        }
        $list .= '</ul>';

        return $list;
    }
}
