<?php

namespace App\Console\Commands\ApplicationLanguageFiles;

use App\Core\Service\LanguageBaseService;
use App\Exceptions\ApiErrorException;
use Illuminate\Console\Command;
use Exception;
use Illuminate\Support\Facades\Log;

class ApplicationLanguageFiles extends Command
{

    protected $signature = 'cron:create-application-language-files'; // fill common.json ...

    protected $description = '';
    private $languageBaseService;

    public function __construct(
        LanguageBaseService $languageBaseService
    )
    {

        $this->languageBaseService = $languageBaseService;
        parent::__construct();
    }

    public function handle()
    {
        try {

            $this->info(date('Y-m-d H:i:s') . ' : ' . date('Y-m-d') . ' LANGUAGE CREATE JSON START');
            $process = $this->languageBaseService->createApplicationLanguageFiles();
            if($process['status'] != 'success'){
                throw new Exception($process['message']) ;

            }
            $this->info(date('Y-m-d H:i:s') . ' : ' . date('Y-m-d') . ' LANGUAGE CREATE JSON FINISHED');

        } catch (Exception $e) {
            $message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage();
            Log::error($message);
            $this->error(date('Y-m-d H:i:s') . ' : ' . date('Y-m-d') . ' ERROR: ' . $message);
        }

    }

}
