<?php

declare(strict_types=1);

namespace Tests\Support;

use App\Framework\Logging\ValueObjects\LogRecord;

/**
 * Simple in-memory log handler for testing
 */
final class TestLogHandler
{
    /** @var array<LogRecord> */
    private array $records = [];

    public function handle(LogRecord $record): void
    {
        $this->records[] = $record;
    }

    /**
     * @return array<LogRecord>
     */
    public function getRecords(): array
    {
        return $this->records;
    }

    public function clear(): void
    {
        $this->records = [];
    }

    public function hasRecordThatContains(string $needle): bool
    {
        foreach ($this->records as $record) {
            if (str_contains($record->message, $needle)) {
                return true;
            }
        }

        return false;
    }

    public function getRecordCount(): int
    {
        return count($this->records);
    }
}
