<?php

namespace FireflyIII\Console\Commands\Upgrade;

use Illuminate\Console\Command;

class UpgradeSkeleton extends Command
{
    use ShowsFriendlyMessages;
    public const string CONFIG_NAME = '480_some_name';

    protected $description = 'SOME DESCRIPTION';

    protected $signature = 'upgrade:UPGRSKELETON {--F|force : Force the execution of this command.}';

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle(): int
    {
        $start = microtime(true);
        if ($this->isExecuted() && true !== $this->option('force')) {
            $this->friendlyInfo('This command has already been executed.');

            return 0;
        }
        $this->friendlyWarning('Congrats, you found the skeleton command. Boo!');

        //$this->markAsExecuted();

        $end = round(microtime(true) - $start, 2);
        $this->info(sprintf('in %s seconds.', $end));

        return 0;
    }

    /**
     * @return bool
     */
    private function isExecuted(): bool
    {
        $configVar = \FireflyIII\Support\Facades\FireflyConfig::get(self::CONFIG_NAME, false);
        if (null !== $configVar) {
            return (bool)$configVar->data;
        }

        return false;
    }


    /**
     *
     */
    private function markAsExecuted(): void
    {
        \FireflyIII\Support\Facades\FireflyConfig::set(self::CONFIG_NAME, true);
    }
}
