<?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 ApplicationLanguageBaseData extends Command
{

    protected $signature = 'cron:create-application-language-base-data'; // tables to translate_base table import data ..

    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 BASE START');
            $process = $this->languageBaseService->createApplicationLanguageBaseData();
            if($process['status'] != 'success'){
                throw new Exception($process['message']) ;

            }
            $this->info(date('Y-m-d H:i:s') . ' : ' . date('Y-m-d') . ' LANGUAGE BASE 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);
        }

    }

}
