<?php

declare(strict_types=1);

namespace apexl\Io\modules\logger;

use apexl\Config\ConfigurationInterface;
use apexl\Io\includes\Module;
use apexl\Io\modules\logger\dto\LoggerConfig;
use apexl\Io\modules\logger\hooks\ConsoleCommands;
use apexl\Io\modules\logger\hooks\errorListener;
use apexl\Io\modules\logger\hooks\whoopsHandlerListener;
use apexl\Io\services\InstallChecker;
use app\vendor\apexl\io\src\Io\interfaces\ProvidesHooksInterface;

class loggerModule extends Module implements ProvidesHooksInterface
{
    public function __construct(
        ConfigurationInterface $config,
        InstallChecker $installChecker,
        private readonly LoggerConfig $loggerConfig
    ) {
        parent::__construct($installChecker, $config);
    }

    public function hooks(): array
    {
        // The command is registered whether or not this install wants the error
        // listeners — catchErrors decides who handles thrown errors, not whether
        // daedalus gets its logging commands.
        $hooks = [
            ConsoleCommands::class,
        ];

        if ($this->loggerConfig->catchErrors) {
            $hooks[] = whoopsHandlerListener::class;
            $hooks[] = errorListener::class;
        }

        return $hooks;
    }
}
