<?php

namespace Sibs\Stargate\Traits;

use Sibs\Stargate\Loggers\SibsLogger;

trait SuppressLogTrait
{
    /**
     * @var bool
     */
    protected $suppressLog = false;

    protected static $DEBUG = 'debug';
    protected static $INFO = 'info';
    protected static $WARNING = 'warning';
    protected static $ERROR = 'error';

    /**
     * Set the value of suppressLog.
     *
     * @return self
     */
    public function setSuppressLog(bool $suppressLog)
    {
        $this->suppressLog = $suppressLog;

        return $this;
    }

    /**
     * Validate and Log.
     */
    protected function validateAndLog(bool $validate, string $logMessage = '', array $context = []): bool
    {
        $logType = (($validate) ? self::$DEBUG : self::$WARNING);
        $this->selfLog(
            $logType,
            $logMessage.' = '.(($validate) ? 'true' : 'false'),
            $context
        );

        return $validate;
    }

    /**
     * Self Log Log.
     */
    protected function selfLog(string $logType, string $logMessage = '', array $context = [])
    {
        if ($this->suppressLog) {
            return;
        }

        SibsLogger::addRecord($logType, $logMessage, $context, 4);
    }
}
