<?php

namespace App\Console\Commands;

use App\Http\Controllers\ConfigSetting;
use Illuminate\Console\Command;

class MakeSettings extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'settings:make';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Load settings from DB to config files';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        /** @var ConfigSetting $settingsController */
        $settingsController = app(ConfigSetting::class);
        //Make settingConfig.php
        if ($settingsController->makeSettings()) {
            $this->info('Updated config/settingConfig.php');
        }
        else {
            $this->error('Failed updating config/settingConfig.php');
        }

        //Make mailTemplate.json
        if ($settingsController->makeEmailTemplateSettings()) {
            $this->info('Updated config/mailTemplate.json');
        }
        else {
            $this->error('Failed updating config/mailTemplate.json');
        }
    }
}
