<?php

namespace Planaday\Utility\Debug\Log;

use Planaday\Config\General\Debug\DebugSettings;
use Planaday\Platform\PlatformAbstraction\UserService;
use Planaday\Utility\PluginData;

class LogCompiler {
	use Logging;

	public function __construct(
		protected DebugSettings $debugSettings,
		protected UserService $userService,
		protected LogScriptBuilder $scriptBuilder,
		protected PluginData $pluginData
	) {}

	public function getScript(): string {
		return $this->scriptBuilder->getScript(
			$this->logger ?? new Logger(),
			$this->getAllowedTypes(),
			$this->userService->isAdmin(),
			implode('.', $this->pluginData->getPluginVersion()),
		);
	}

	/**
	 * @return string[]
	 */
	private function getAllowedTypes(): array{
		$allowedTypes = ['error', 'warning'];
		if ($this->userService->isAdmin()) {
			if ($this->debugSettings->isSendDebugLogs()){
				return ['all'];
			}

			$allowedTypes[] = 'info';
		}

		return $allowedTypes;
	}
}