<?php if ( !defined('ENVIRONMENT') ) exit('Only STG can run script!');

    class Log {
        
        // Class'es vars:
        private $message = NULL;
        
        // Recived vars from `ubilling.cls`:
        private $config;

        // Constructor:
        public function __construct($data) {
            // Put all recived data to specified vars:
            foreach ($data as $key => $value) {
                $this->$key = $value;
            }
        }

        public function message($class, $string, $level = NULL) {
            $message = date('Y-m-d H:i:s') . ' - [' . $class. '] - ';
            switch ($level) {
                case 'api':
                    if ( FALSE ) {
                        $message .= 'MikroTik:';
                    } else return TRUE;
                    break;
                case 'error':
                    $message .= 'Error:';
                    break;
                case 'success':
                    $message .= 'Success:';
                    break;
                case 'debug':
                    if ( $this->config['debug'] ) {
                        $message .= 'Debug:';
                    } else return TRUE;
                    break;
            }
            $nbsp = ( empty($level) ) ? NULL : ' ';
            $this->message .= $message . $nbsp . $string . PHP_EOL;
        }
        
        public function write() {
            if ( $this->config['enabled'] ) {
                file_put_contents($this->config['path'] . '/' . $this->config['file'], $this->message, FILE_APPEND | LOCK_EX);
            } else return TRUE;
        }
        
    }
?>