<?php

declare(strict_types=1);

namespace App\Application\System;

use App\Framework\Core\Events\ApplicationBooted;
use App\Framework\Core\Events\OnEvent;
use App\Framework\Logging\DefaultLogger;
use App\Framework\Logging\ValueObjects\LogContext;

final readonly class BootLogger
{
    public function __construct(
        private DefaultLogger $logger
    ) {
    }

    #[OnEvent]
    public function log(ApplicationBooted $event): void
    {
        #echo "[Boot] {$event->bootTime->format('H:i:s')} | Env: {$event->environment}\n";

        $context = LogContext::withData([
            'boot_time' => $event->bootTime->format('Y-m-d H:i:s.u'),
            'environment' => $event->environment,
            'memory_usage' => memory_get_usage(true),
            'peak_memory' => memory_get_peak_usage(true),
        ])->addTags('application', 'boot');

        $this->logger->info('Application booted', $context);
    }
}
