<?php

namespace Fifa\ConnectId\Sdk\Registration;

use Psr\Log\LoggerInterface;

class PrefixedLogger implements LoggerInterface
{
    /**
     * @var LoggerInterface
     */
    private $logger;
    
    /**
     * @var string
     */
    private $prefix;

    public function __construct(LoggerInterface $logger, string $prefix) {
        $this->logger = $logger;
        $this->prefix = $prefix;
    }

    /**
     * System is unusable.
     *
     * @param string  $message
     * @param array $context
     *
     * @return void
     */
    public function emergency($message, array $context = array()) : void
    {
        $this->logger->emergency($this->applyPrefix($message), $context);
    }

    /**
     * Action must be taken immediately.
     *
     * Example: Entire website down, database unavailable, etc. This should
     * trigger the SMS alerts and wake you up.
     *
     * @param string  $message
     * @param array $context
     *
     * @return void
     */
    public function alert($message, array $context = array()) : void
    {
        $this->logger->alert($this->applyPrefix($message), $context);
    }

    /**
     * Critical conditions.
     *
     * Example: Application component unavailable, unexpected exception.
     *
     * @param string  $message
     * @param array $context
     *
     * @return void
     */
    public function critical($message, array $context = array()) : void
    {
        $this->logger->critical($this->applyPrefix($message), $context);
    }

    /**
     * Runtime errors that do not require immediate action but should typically
     * be logged and monitored.
     *
     * @param string  $message
     * @param array $context
     *
     * @return void
     */
    public function error($message, array $context = array()) : void
    {
        $this->logger->error($this->applyPrefix($message), $context);
    }

    /**
     * Exceptional occurrences that are not errors.
     *
     * Example: Use of deprecated APIs, poor use of an API, undesirable things
     * that are not necessarily wrong.
     *
     * @param string  $message
     * @param array $context
     *
     * @return void
     */
    public function warning($message, array $context = array()) : void
    {
        $this->logger->warning($this->applyPrefix($message), $context);
    }

    /**
     * Normal but significant events.
     *
     * @param string  $message
     * @param array $context
     *
     * @return void
     */
    public function notice($message, array $context = array()) : void
    {
        $this->logger->notice($this->applyPrefix($message), $context);
    }

    /**
     * Interesting events.
     *
     * Example: User logs in, SQL logs.
     *
     * @param string  $message
     * @param array $context
     *
     * @return void
     */
    public function info($message, array $context = array()) : void
    {
        $this->logger->info($this->applyPrefix($message), $context);
    }

    /**
     * Detailed debug information.
     *
     * @param string $message
     * @param array $context
     *
     * @return void
     */
    public function debug($message, array $context = array()) : void
    {
        $this->logger->debug($this->applyPrefix($message), $context);
    }

    /**
     * Logs with an arbitrary level.
     *
     * @param mixed $level
     * @param string $message
     * @param array $context
     *
     * @return void
     */
    public function log($level, $message, array $context = array()) : void
    {
        $this->logger->log($level, $this->applyPrefix($message), $context);
    }

    private function applyPrefix($message) : string {
        return $this->prefix . $message;
    }
}