<?php

namespace Solspace\Freeform\Bundles\Digest\Providers;

use Monolog\Logger;
use Psr\Log\LoggerInterface;
use Solspace\Freeform\Freeform;
use Solspace\Freeform\Models\Settings;
use Solspace\Freeform\Services\SettingsService;

class DigestLoggerProvider
{
    public const LOG_FILE = 'freeform-email.log';

    private int $level;

    public function __construct(
        SettingsService $settingsService,
    ) {
        $this->level = match ($settingsService->getSettingsModel()->loggingLevel) {
            Settings::LOGGING_LEVEL_INFO => Logger::INFO,
            Settings::LOGGING_LEVEL_DEBUG => Logger::DEBUG,
            default => Logger::ERROR,
        };
    }

    public function getLogger(): LoggerInterface
    {
        $logCategory = 'digest';

        return Freeform::getInstance()
            ->logger
            ->getLogger(
                $logCategory,
                self::LOG_FILE,
                $this->level
            )
        ;
    }
}
