<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Carbon\Carbon;

abstract class AbstractCommand extends Command
{
    /**
     * A friendly name of the command that will be used when loggin messages.
     *
     * @var string
     */
    protected $command_title = 'AbstractCommand';

    /**
     * Returns the formated timestamp that gets used in the log line.
     *
     * @return string
     */
    public function getFormattedDate()
    {
        // We are storing the formatted time
        $now = Carbon::now()->toDateTimeString();

        return '['.$now.'] ['.$this->command_title.'] ';
    }

    /**
     * Overrides the log command by adding the timestamp & command name.
     *
     * @return null
     */
    public function log($message)
    {
        parent::log($this->getFormattedDate().$message);
    }

    /**
     * Overrides the info command by adding the timestamp & command name.
     *
     * @param string $message
     * @param int|null $verbosity
     * @return null
     */
    public function info($message, $verbosity = null)
    {
        parent::info($this->getFormattedDate().$message, $verbosity);
    }

    /**
     * Overrides the error command by adding the timestamp & command name.
     *
     * @param string $message
     * @param int|null $verbosity
     * @return null
     */
    public function error($message, $verbosity = null)
    {
        parent::error($this->getFormattedDate().$message, $verbosity);
    }
}
