<?php

namespace App\Classes\General;

use Illuminate\Support\Facades\Log;

class LogHelper
{
    private String $channelName;

    public static function channel($channelName): self
    {
        $logHelper = new self;
        $logHelper->channelName = $channelName;
        return $logHelper;
    }

    public function info($message)
    {
        $envVar = env('LARAVEL_VAPOR_ENABLED');
        $isLocal = env('VAPOR_ENV') === 'local';
        Log::info("Info: " . json_encode($message));
        Log::info("Info: {$message}， channelName： {$this->channelName},  envVar {$envVar}");
        if ($envVar && !$isLocal) {
            Log::channel($this->channelName.'_vapor')->info($message);
        }
        else{
            Log::channel($this->channelName)->info($message);
        }
    }

    public function warning($message)
    {
        $envVar = env('LARAVEL_VAPOR_ENABLED');
        $isLocal = env('VAPOR_ENV') === 'local';
        Log::info("Warning: {$message}， channelName： {$this->channelName},  envVar {$envVar}");
        if ($envVar && !$isLocal) {
            Log::channel($this->channelName . '_vapor')->warning($message);
        } else {
            Log::channel($this->channelName)->warning($message);
        }
    }

    public function error($message)
    {
        $envVar = env('LARAVEL_VAPOR_ENABLED');
        $isLocal = env('VAPOR_ENV') === 'local';
        Log::info("Error: {$message}， channelName： {$this->channelName},  envVar {$envVar}");
        if ($envVar && !$isLocal) {
            Log::channel($this->channelName . '_vapor')->error($message);
        } else {
            Log::channel($this->channelName)->error($message);
        }
    }
}
