<?php

declare(strict_types=1);

namespace kodorvan\edabil;

// Files of the project
use kodorvan\edabil\models\account,
	kodorvan\edabil\models\telegram\middlewares,
	kodorvan\edabil\models\telegram\commands,
	kodorvan\edabil\models\telegram\buttons,
	kodorvan\edabil\models\telegram\chat,
	kodorvan\edabil\models\telegram\account as telegram_account,
	kodorvan\edabil\models\telegram\settings,
	kodorvan\edabil\models\telegram\tariff,
	kodorvan\edabil\models\acquirings\yookassa,
	kodorvan\edabil\models\enumerations\tariff as tariff_type,
	kodorvan\edabil\models\telegram\processes\settings\chat\memory\messages as processes_settings_chat_memory_messages,
	kodorvan\edabil\models\telegram\commands\start as command_start,
	kodorvan\edabil\models\telegram\commands\network as command_network,
	kodorvan\edabil\models\telegram\commands\account as command_account,
	kodorvan\edabil\models\telegram\commands\society as command_society,
	kodorvan\edabil\models\telegram\commands\language as command_language,
	kodorvan\edabil\models\telegram\middlewares\account as middleware_account,
	kodorvan\edabil\models\telegram\middlewares\language as middleware_language,
	kodorvan\edabil\models\telegram\middlewares\localization as middleware_localization,
	kodorvan\edabil\models\telegram\middlewares\authorizations as middleware_authorizations,
	kodorvan\edabil\models\telegram\middlewares\settings as middleware_settings,
	kodorvan\edabil\models\telegram\middlewares\chat as middleware_chat,
	kodorvan\edabil\models\telegram\middlewares\network as middleware_network,
	kodorvan\edabil\models\telegram\middlewares\message as middleware_message,
	kodorvan\edabil\models\telegram\middlewares\welcome as middleware_welcome;

// Library for languages support
use mirzaev\languages\language;

// Framework for PHP
use mirzaev\minimal\core,
	mirzaev\minimal\route;

// Framework for Telegram
use SergiX44\Nutgram\Nutgram as telegram,
	SergiX44\Nutgram\Configuration as telegram_settings,
	SergiX44\Nutgram\RunningMode\Webhook as webhook;

// Enabling debugging
/* ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1); */

// Initializing path to the public directory 
define('INDEX', __DIR__. DIRECTORY_SEPARATOR	. '..');

// Initializing path to the project root directory
define('ROOT',  INDEX . DIRECTORY_SEPARATOR	. '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR	. '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR);

// Initializing path to the directory of views 
define('VIEWS', INDEX . DIRECTORY_SEPARATOR	. '..' . DIRECTORY_SEPARATOR . 'views');

// Initializing path to the directory of settings 
define('SETTINGS', INDEX . DIRECTORY_SEPARATOR	. '..' . DIRECTORY_SEPARATOR . 'settings');

// Initializing system settings 
require SETTINGS . DIRECTORY_SEPARATOR . 'system.php';

// Initializing path to the directory of the storage 
define('STORAGE', INDEX . DIRECTORY_SEPARATOR	. '..' . DIRECTORY_SEPARATOR . 'storage');

// Initializing path to the databases directory
define('DATABASES', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'databases');

// Initializing path to the localizations directory
define('LOCALIZATIONS', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'localizations');

// Initiailizing Telegram key
define('TELEGRAM', require(SETTINGS . DIRECTORY_SEPARATOR . 'telegram.php'));

// Initializing dependencies
require ROOT . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';

// Initializing the robot
$robot = new telegram(
	token: TELEGRAM['key'],
	config: new telegram_settings(
		botName: TELEGRAM['name'],
	)
);

$webhook = new webhook(secretToken: TELEGRAM['password']);
$webhook->setSafeMode(true);

$robot->setRunningMode($webhook);

$robot->middleware(middleware_account::class);
$robot->middleware(middleware_language::class);
$robot->middleware(middleware_localization::class);
$robot->middleware(middleware_authorizations::class);

// Start
$robot->registerCommand(command_start::class);

// Society
$robot->registerCommand(command_society::class);

/* $robot->registerMyCommands(); */

// Starting chat-robot
$robot->run();
