<?php

declare(strict_types=1);

namespace Buggregator\Trap;

/**
 * @internal
 */
class Info
{
    public const NAME = 'Buggregator Trap';
    public const LOGO_CLI_COLOR = <<<CONSOLE
        \e[44;97;1m                                    \e[0m
        \e[44;97;1m      ▄█▀                  ▀█▄      \e[0m
        \e[44;97;1m     ▐█▌      ▄█▀▀▀▀█▄      ▐█▌     \e[0m
        \e[44;97;1m     ██   ▀▄ █        █ ▄▀   ██     \e[0m
        \e[44;97;1m    ▐█▌     █▀▀▀▀▀▀▀▀▀▀█     ▐█▌    \e[0m
        \e[44;97;1m   ▄█▀     ▐▌  ▀▄  ▄▀  ▐▌     ▀█▄   \e[0m
        \e[44;97;1m   ▀█▄   ▄▄█     ██     █▄▄   ▄█▀   \e[0m
        \e[44;97;1m    ▐█▌     █  ▄▀  ▀▄  █     ▐█▌    \e[0m
        \e[44;97;1m     ██      █▄      ▄█      ██     \e[0m
        \e[44;97;1m     ▐█▌   ▄▀  ▀▄▄▄▄▀  ▀▄   ▐█▌     \e[0m
        \e[44;97;1m      ▀█▄                  ▄█▀      \e[0m
        \e[44;97;1m                                    \e[0m
        CONSOLE;
    public const TRAP_ROOT = __DIR__ . '/..';
    private const VERSION = 'experimental';

    /**
     * Returns the version of the Trap.
     *
     * @return non-empty-string
     */
    public static function version(): string
    {
        /** @var non-empty-string|null $cache */
        static $cache = null;

        if ($cache !== null) {
            return $cache;
        }

        $fileContent = \file_get_contents(self::TRAP_ROOT . '/resources/version.json');

        if ($fileContent === false) {
            return $cache = self::VERSION;
        }

        /** @var mixed $version */
        $version = \json_decode($fileContent, true)['.'] ?? null;

        return $cache = \is_string($version) && $version !== ''
            ? $version
            : self::VERSION;
    }
}
