<?php

namespace Sibs\Sibs\Utils;

use Exception;

class SibsException extends Exception
{
    /**
     * @var string
     */
    protected $details;

    /**
     * @param string $details
     * @param ?string $logFile
     */
    public function __construct(string $details, string $logFile = null)
    {
        parent::__construct($details);

        $this->details = $details;

        if (!empty($logFile)) {
            SibsLog::setNameFile($logFile);
        }

        SibsLog::log($this->details, SibsLog::LEVEL_ERROR, [], 3);
    }

    /**
     * Get Error Message
     *
     * @return string
     */
    public function getErrorMessage()
    {
        return "SIBS Error: {$this->details}";
    }
}
