<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Notifications\SlackNotification;
use Illuminate\Support\Facades\Notification;
use Illuminate\Support\Facades\Log;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

abstract class BaseCommand extends Command
{

    /**
     * Whether or not this automation should run when Creatia is in enterprise mode.
     *
     * @var boolean
     */
    protected $notEnterprise = false;

    public function __construct()
    {
        // When doing commands the environment requires reloading.
        app()->loadEnvironmentFrom(base_path('.env'));

        if(env('APP_ENV', null) === null) {
            
            app()->loadEnvironmentFrom('/etc/creatia/');
        }

        parent::__construct();
    }

    public function isEnabled(): bool
    {

        // Enterprise rollouts should not be able to run specific commands, ever.
        if($this->notEnterprise && config('app.enterprise')) {
            
            return false;

        }

        return true;
    }

    /**
     * Send a notification.
     *
     * @return void
     */
    public static function notify($_message)
    {
        Notification::route('slack', config('creatia.webhook.standard'))->notify(new SlackNotification($_message));
    }

    public function log_event($_message, $_values)
    {        
        Log::info("($this->signature) MSG: `$_message`", $_values);
    }

    public function log_error($_message, $_values)
    {        
        Log::error("($this->signature) MSG: `$_message`", $_values);
    }

    public function log_warning($_message, $_values)
    {        
        Log::warning("($this->signature) MSG: `$_message`", $_values);
    }

   
}
