<?php

declare(strict_types=1);

namespace kodorvan\edabil\models\telegram\middlewares;

// Files of the project
use kodorvan\edabil\models\core,
	kodorvan\edabil\models\account,
	kodorvan\edabil\models\localization as model,
	kodorvan\edabil\models\authorizations;

// The library for languages support
use mirzaev\languages\language;

// The library for escaping all markdown symbols
use function mirzaev\unmarkdown;

// Framework for Telegram
use SergiX44\Nutgram\Nutgram as telegram,
	SergiX44\Nutgram\Telegram\Properties\ParseMode as mode;

// Built-in libraries
use Exception as exception,
	Error as error;

/**
 * Telegram middleware: localization
 *
 * @package kodorvan\edabil\models\telegram\middlewares
 *
 * @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
 * @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
 */
final class localization extends core
{
	/**
	 * Localization
	 *
	 * Implement the account language and initialize the localization file
	 *
	 * @param telegram $robot
	 * @param $next
	 *
	 * @return void
	 */
	public function __invoke(telegram $robot, $next): void
	{
		// Is the process stopped?
		if ($robot->get('stop')) return;

		// Initializing the language
		$language = $robot->get('language') ?? LANGUAGE_DEFAULT ?? language::en;

		// Initializing the localization
		$localization = new model($language);

		// Writing localization into the robot variable
		$robot->set('localization', $localization);

		// Continuation of the process
		$next($robot);
	}
}
