<?php

declare(strict_types=1);

namespace Apexl\Io\Notifier\Logger;

use Apexl\Io\Logger\Interfaces\LoggerInterface;

class ErrorLogLogger implements LoggerInterface
{
    public function emergency($message, array $context = []): void
    {
        $this->errorLog($message, $context, E_USER_ERROR);
    }

    public function alert($message, array $context = []): void
    {
        $this->errorLog($message, $context, E_USER_ERROR);
    }

    public function critical($message, array $context = []): void
    {
        $this->errorLog($message, $context, E_USER_ERROR);
    }

    public function error($message, array $context = []): void
    {
        $this->errorLog($message, $context, E_USER_ERROR);
    }

    public function warning($message, array $context = []): void
    {
        $this->errorLog($message, $context, E_USER_WARNING);
    }

    public function notice($message, array $context = []): void
    {
        $this->errorLog($message, $context, E_USER_NOTICE);
    }

    public function info($message, array $context = []): void
    {
        $this->errorLog($message, $context, E_USER_NOTICE);
    }

    public function debug($message, array $context = []): void
    {
        $this->errorLog($message, $context, E_USER_NOTICE);
    }

    public function log($level, $message, array $context = []): void
    {
        $this->errorLog($message, $context, E_USER_NOTICE);
    }

    private function errorLog(string $message, array $context, int $level): void
    {
        $message = sprintf('%s [%s]', $message, json_encode($context, JSON_PRETTY_PRINT));

        error_log($message, $level);
    }
}
