<?php

declare(strict_types=1);

namespace mirzaev\deeproots\models\telegram\processes\question;

// Files of the project
use mirzaev\deeproots\models\core,
	mirzaev\deeproots\models\question,
	mirzaev\deeproots\models\question\localization as question_localization,
	mirzaev\deeproots\models\answer,
	mirzaev\deeproots\models\enumerations\language,
	mirzaev\deeproots\models\telegram\commands,
	mirzaev\deeproots\models\telegram\buttons\question\search as buttons_question_search,
	mirzaev\deeproots\models\telegram\traits\escape;

// Baza database
use mirzaev\baza\record;

// Framework for Telegram
use Zanzara\Context as context,
	Zanzara\Telegram\Type\Message as message;

// Event-driven library for PHP
use function React\Async\await;

/**
 * Question create (system) 
 *
 * @package mirzaev\deeproots\models\telegram\processes\question
 *
 * @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
 * @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
 */
final class search extends core
{
	use escape;

	/**
	 * Process
	 *
	 * @var const string PROCESS Name of the process in the telegram user buffer
	 */
	public const string PROCESS = 'system_questions_search';

	/**
	 * Start
	 *
	 * Starting the search process
	 *
	 * @param context $context Request data from Telegram
	 * @param int|null $identifier Identifier of the question
	 *
	 * @return void
	 */
	public static function start(context $context, ?int $identifier = null): void
	{
		// Initializing the account
		$account = $context->get('account');

		if ($account instanceof record) {
			// Initialized the account

			// Initializing language 
			$language = $context->get('language');

			if ($language instanceof language) {
				// Initialized language

				// Initializing localization 
				$localization = $context->get('localization');

				if ($localization) {
					// Initialized localization

					// Reading from the telegram user buffer
					$context->getUserDataItem(static::PROCESS)
						->then(function (?array $search) use ($context, $account, $language, $localization, $identifier) {
							// Readed from the telegram user buffer

							if ($search) {
								// Found started search process

								// Sending the message
								$context->sendMessage('🗂 *' . $localization[static::PROCESS . '_continued'] . '*')
									->then(function (message $message) use ($context, $account, $language, $localization) {
										// Sended the message

										// Searching
										static::search($context);
									});
							} else {
								// Not found started search process

								// Initializing the question search buffer
								$search = [
									'identifier' => $identifier,
									'text' => null,
									'A' => null,
									'B' => null,
									'C' => null,
									'D' => null,
									'page' => 0
								];

								// Writing to the telegram user buffer
								$context->setUserDataItem(static::PROCESS, $search)
									->then(function () use ($context, $account, $localization) {
										// Writed to the telegram user buffer

										// Sending the message
										$context->sendMessage('🗂 *' . $localization[static::PROCESS . '_started'] . '*')
											->then(function (message $message) use ($context, $account, $localization) {
												// Sended the message

												// Searching
												static::search($context);
											});
									});
							}
						});
				} else {
					// Not initialized localization

					// Sending the message
					$context->sendMessage('⚠️ *Failed to initialize localization*')
						->then(function (message $message) use ($context) {
							// Sended the message

							// Ending the conversation process
							$context->endConversation();
						});
				}
			} else {
				// Not initialized language

				// Sending the message
				$context->sendMessage('⚠️ *Failed to initialize language*')
					->then(function (message $message) use ($context) {
						// Sended the message

						// Ending the conversation process
						$context->endConversation();
					});
			}
		} else {
			// Not initialized the account

			// Sending the message
			$context->sendMessage('⚠️ *Failed to initialize the account*')
				->then(function (message $message) use ($context) {
					// Sended the message

					// Ending the conversation process
					$context->endConversation();
				});
		}
	}

	/**
	 * End
	 *
	 * Ending the search process
	 *
	 * @param context $context Request data from Telegram
	 *
	 * @return void
	 */
	public static function end(context $context): void
	{
		// Initializing the account
		$account = $context->get('account');

		if ($account instanceof record) {
			// Initialized the account

			// Initializing localization 
			$localization = $context->get('localization');

			if ($localization) {
				// Initialized localization

				// Reading from the telegram user buffer
				$context->getUserDataItem(static::PROCESS)
					->then(function (?array $search) use ($context, $localization) {
						// Readed from the telegram user buffer

						if ($search) {
							// Found started search process

							// Deleting from the telegram user buffer
							$context->deleteUserDataItem(static::PROCESS, $search)
								->then(function () use ($context, $search, $localization) {
									// Deleted from the telegram user buffer

									// Sending the message
									$context->sendMessage('🗂 *' . $localization[static::PROCESS . '_ended'] . '*')
										->then(function (message $message) use ($context) {
											// Sended the message

											// Ending the conversation process
											$context->endConversation();

											// Sending the system questions menu
											commands::system_questions($context);
										});
								});
						} else {
							// Not found started search process

							// Ending the conversation process
							$context->endConversation();

							// Sending the system questions menu
							commands::system_questions($context);
						}
					});
			} else {
				// Not initialized localization

				// Sending the message
				$context->sendMessage('⚠️ *Failed to initialize localization*')
					->then(function (message $message) use ($context) {
						// Sended the message

						// Ending the conversation process
						$context->endConversation();
					});
			}
		} else {
			// Not initialized the account

			// Sending the message
			$context->sendMessage('⚠️ *Failed to initialize the account*')
				->then(function (message $message) use ($context) {
					// Sended the message

					// Ending the conversation process
					$context->endConversation();
				});
		}
	}

	/**
	 * Search
	 *
	 * Sends the list of found questions and menu with parameters
	 *
	 * @param context $context Request data from Telegram
	 *
	 * @return void
	 */
	protected static function search(context $context): void
	{
		// Initializing the account
		$account = $context->get('account');

		if ($account instanceof record) {
			// Initialized the account

			// Initializing language 
			$language = $context->get('language');

			if ($language) {
				// Initialized language

				// Initializing localization 
				$localization = $context->get('localization');

				if ($localization) {
					// Initialized localization

					// Reading from the telegram user buffer
					$context->getUserDataItem(static::PROCESS)
						->then(function (?array $search) use ($context, $account, $language, $localization) {
							// Readed from the telegram user buffer

							if ($search) {
								// Found started search process

								// Initializing the buffer of generated keyboard with languages
								$keyboard = [
									[
										[
											'text' => empty($search['identifier']) ? '🔴 ' . $localization[static::PROCESS . '_button_identifier'] : '🟢 ' . $localization[static::PROCESS . '_button_identifier'] . ': ' . $search['identifier'],
											'callback_data' => static::PROCESS . '_identifier'
										]
									],
									[
										[
											'text' => empty($search['text']) ? '🔴 ' . $localization[static::PROCESS . '_button_text'] : '🟢 ' . $localization[static::PROCESS . '_button_text'] . ': ' . $search['text'],
											'callback_data' => static::PROCESS . '_text'
										]
									],
									[
										[
											'text' => empty($search['A']) ? '🔴 ' . $localization[static::PROCESS . '_button_a'] : '🟢 ' . $localization[static::PROCESS . '_button_a'] . ': ' . $search['A'],
											'callback_data' => static::PROCESS . '_a'
										]
									],
									[
										[
											'text' => empty($search['B']) ? '🔴 ' . $localization[static::PROCESS . '_button_b'] : '🟢 ' . $localization[static::PROCESS . '_button_b'] . ': ' . $search['B'],
											'callback_data' => static::PROCESS . '_b'
										]
									],
									[
										[
											'text' => empty($search['C']) ? '🔴 ' . $localization[static::PROCESS . '_button_c'] : '🟢 ' . $localization[static::PROCESS . '_button_c'] . ': ' . $search['C'],
											'callback_data' => static::PROCESS . '_c'
										]
									],
									[
										[
											'text' => empty($search['D']) ? '🔴 ' . $localization[static::PROCESS . '_button_d'] : '🟢 ' . $localization[static::PROCESS . '_button_d'] . ': ' . $search['D'],
											'callback_data' => static::PROCESS . '_d'
										]
									]
								];

								// Ending the conversation process
								$context->endConversation()
									->then(function () use ($context, $account, $language, $localization, $search, $keyboard) {
										// Deinitialized the conversation process

										// Initializing the question model
										$model_question = new question;

										// Initializing amount of questions for reading per page
										$page = SYSTEM_QUESTIONS_SEARCH_PAGE;

										if (
											empty($search['identifier']) &&
											empty($search['text']) &&
											empty($search['A']) &&
											empty($search['B']) &&
											empty($search['C']) &&
											empty($search['D'])
										) {
											// Each parameter is empty

											// Search for questions
											$questions = $model_question->database->read(
												amount: $page + 1,
												offset: $search['page'] < 1 ? 0 : $page * $search['page']
											);
										} else {
											// The search buffer has at least one parameter

											// Search for questions
											$questions = $model_question->database->read(
												filter: function (record $question) use ($search) {
													// Initializing the matched buffer
													$matched = false;

													if (!empty($search['identifier'])) {
														// Requested search by identifier

														if ($question->identifier === $search['identifier']) {
															// Identifier matched

															// Reinitializing the matched buffer
															$matched = true;
														} else {
															// Identifier not matched

															// Exit (success)
															return false;
														}
													}

													if (
														!empty($search['text']) ||
														!empty($search['A']) ||
														!empty($search['B']) ||
														!empty($search['C']) ||
														!empty($search['D'])
													) {
														// Requested search with localizations

														// Initializing the buffer of result for localizations matchings process
														$result = false;

														foreach (language::cases() as $case) {
															// Iterating over languages

															// Initializing the question localization model
															$model_question_localization = new question_localization($case);

															// Initializing localization
															$localization = $model_question_localization->database->read(
																filter: fn(record $localization) => $localization->identifier === $question->identifier,
																amount: 1
															)[0] ?? null;

															if ($localization instanceof record) {
																// Initialized the question localization

																if (!empty($search['text'])) {
																	// Requested search by localizations text

																	// Splitting the localization text into parts
																	$parts = preg_split('/[\s]/', $localization->text);

																	foreach ($parts as $part) {
																		// Iterating over localization text parts

																		if (levenshtein($part, $search['text']) <= SYSTEM_QUESTIONS_SEARCH_QUESTION_TEXT_LEVENSHTEIN_DISTANCE) {
																			// Text matched by Levenshtein function

																			// Reinitializing the matched buffer
																			$result = true;

																			// Exit (success)
																			break 1;
																		}
																	}

																	if ($result) {
																		// Text matched by Levenshtein function

																		// Reinitializing the matched buffer
																		$matched = true;
																	} else {
																		// Text not matched by Levenshtein function

																		// Exit (success)
																		return false;
																	}
																}

																if (!empty($search['A'])) {
																	// Requested search by localizations A

																	// Initializing the result status
																	$result = false;

																	// Splitting the localization A into parts
																	$parts = preg_split('/[\s]/', $localization->A);

																	foreach ($parts as $part) {
																		// Iterating over localization A parts

																		if (levenshtein($part, $search['A']) <= SYSTEM_QUESTIONS_SEARCH_QUESTION_A_LEVENSHTEIN_DISTANCE) {
																			// A matched by Levenshtein function

																			// Reinitializing the matched buffer
																			$result = true;

																			// Exit (success)
																			break 1;
																		}
																	}

																	if ($result) {
																		// A matched by Levenshtein function

																		// Reinitializing the matched buffer
																		$matched = true;
																	} else {
																		// A not matched by Levenshtein function

																		// Exit (success)
																		return false;
																	}
																}

																if (!empty($search['B'])) {
																	// Requested search by localizations B

																	// Initializing the result status
																	$result = false;

																	// Splitting the localization B into parts
																	$parts = preg_split('/[\s]/', $localization->B);

																	foreach ($parts as $part) {
																		// Iterating over localization B parts

																		if (levenshtein($part, $search['B']) <= SYSTEM_QUESTIONS_SEARCH_QUESTION_B_LEVENSHTEIN_DISTANCE) {
																			// B matched by Levenshtein function

																			// Reinitializing the matched buffer
																			$result = true;

																			// Exit (success)
																			break 1;
																		}
																	}

																	if ($result) {
																		// B matched by Levenshtein function

																		// Reinitializing the matched buffer
																		$matched = true;
																	} else {
																		// B not matched by Levenshtein function

																		// Exit (success)
																		return false;
																	}
																}

																if (!empty($search['C'])) {
																	// Requested search by localizations C

																	// Initializing the result status
																	$result = false;

																	// Splitting the localization C into parts
																	$parts = preg_split('/[\s]/', $localization->C);

																	foreach ($parts as $part) {
																		// Iterating over localization C parts

																		if (levenshtein($part, $search['C']) <= SYSTEM_QUESTIONS_SEARCH_QUESTION_C_LEVENSHTEIN_DISTANCE) {
																			// C matched by Levenshtein function

																			// Reinitializing the matched buffer
																			$result = true;

																			// Exit (success)
																			break 1;
																		}
																	}

																	if ($result) {
																		// C matched by Levenshtein function

																		// Reinitializing the matched buffer
																		$matched = true;
																	} else {
																		// C not matched by Levenshtein function

																		// Exit (success)
																		return false;
																	}
																}

																if (!empty($search['D'])) {
																	// Requested search by localizations D

																	// Initializing the result status
																	$result = false;

																	// Splitting the localization D into parts
																	$parts = preg_split('/[\s]/', $localization->D);

																	foreach ($parts as $part) {
																		// Iterating over localization D parts

																		if (levenshtein($part, $search['D']) <= SYSTEM_QUESTIONS_SEARCH_QUESTION_D_LEVENSHTEIN_DISTANCE) {
																			// D matched by Levenshtein function

																			// Reinitializing the matched buffer
																			$result = true;

																			// Exit (success)
																			break 1;
																		}
																	}

																	if ($result) {
																		// D matched by Levenshtein function

																		// Reinitializing the matched buffer
																		$matched = true;
																	} else {
																		// D not matched by Levenshtein function

																		// Exit (success)
																		return false;
																	}
																}
															}
														}

														// Reinitializing the matched buffer
														$matched = $result;
													}

													// Exit (success)
													return $matched;
												},
												amount: $page + 1,
												offset: $search['page'] < 1 ? 0 : $page * $search['page']
											);
										}

										// Initializing the next page existence status
										$next = count($questions) > $page;

										// Deleting the additional readed questions 
										unset($questions[$page]);

										// Sending the message
										$context->sendMessage(
											'🔍 *' . $localization[static::PROCESS . '_title'] . '*',
											[
												'reply_markup' => [
													'inline_keyboard' => $keyboard,
													'disable_notification' => true,
													'remove_keyboard' => true
												],
											]
										)->then(function (message $message) use ($context, $account, $language, $localization, $search, $page, $next, $questions) {
											// Sended the message

											if (count($questions) > 0) {
												// Initialized questions

												foreach ($questions as $question) {
													// Iterating over found questions

													/* // Initializing the question localization model by the account language
													$model_question_localization = new question_localization(language::{$account->language ?? LANGUAGE_DEFAULT} ?? language::{LANGUAGE_DEFAULT});

													// Initializing the question localization
													$question_localization = $model_question_localization->database->read(
														filter: fn(record $localization) => $localization->identifier === $question->identifier,
														amount: 1
													)[0] ?? null;

													if (is_null($question_localization)) {
														// Failed to initialize the question localization by the account language

														// Reinitializing the question localization model by the default language
														$model_question_localization = new question_localization(language::{LANGUAGE_DEFAULT});

														// Initializing the question localization
														$question_localization = $model_question_localization->database->read(
															filter: fn(record $localization) => $localization->identifier === $question->identifier,
															amount: 1
														)[0] ?? null;

														if (is_null($question_localization)) {
															// Failed to initialize the question localization by the default language

															// Sending the message
															await($context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_localized'] . '* \(' . $question->identifier . '\)')
																->then(function (message $message) use ($context) {
																	// Sended the message

																	// Ending the conversation process
																	$context->endConversation();
																}));

															// Processing the next question
															continue;
														}
													} */

													// Initializing the message text
													$text = static::message(
														question: $question,
														localization: $localization
													);

													// Initializing the message keyboard
													$keyboard = static::keyboard(
														question: $question,
														localization: $localization
													);

													// Sending the message
													await($context->sendMessage(
														$text,
														[
															'reply_markup' => [
																'inline_keyboard' => $keyboard,
																'disable_notification' => true,
																'remove_keyboard' => true
															],
														]
													));
												}

												if ($next) {
													// Exists the next page 

													// Sending the message
													$context->sendMessage(
														'🔎 *' . $localization[static::PROCESS . '_page_next_exists'] . '*',
														[
															'reply_markup' => [
																'inline_keyboard' => [
																	[
																		[
																			'text' => '🔒 ' . $localization[static::PROCESS . '_button_end'],
																			'callback_data' => static::PROCESS . '_end'
																		]
																	],
																	[
																		[
																			'text' => '📤 ' . $localization[static::PROCESS . '_button_page_next'] . ': ' . ++$search['page'],
																			'callback_data' => static::PROCESS . '_next'
																		]
																	]
																],
																'disable_notification' => true,
																'remove_keyboard' => true
															],
														]
													)->then(function (message $message) use ($context) {
														// Sended the message

														// Ending the conversation process
														$context->endConversation();
													});
												} else {
													// Not exists the next page

													// Sending the message
													$context->sendMessage(
														'🔎 *' . $localization[static::PROCESS . '_page_next_not_exists'] . '*',
														[
															'reply_markup' => [
																'inline_keyboard' => [
																	[
																		[
																			'text' => '🔒 ' . $localization[static::PROCESS . '_button_end'],
																			'callback_data' => static::PROCESS . '_end'
																		]
																	]
																],
																'disable_notification' => true,
																'remove_keyboard' => true
															],
														]
													)->then(function (message $message) use ($context) {
														// Sended the message

														// Ending the conversation process
														$context->endConversation();
													});
												}
											} else {
												// Not initialized questions

												// Sending the message
												$context->sendMessage(
													'⚠️ *' . $localization[static::PROCESS . '_empty'] . '*',
													[
														'reply_markup' => [
															'inline_keyboard' => [
																[
																	[
																		'text' => '🔒 ' . $localization[static::PROCESS . '_button_end'],
																		'callback_data' => static::PROCESS . '_end'
																	]
																]
															],
															'disable_notification' => true,
															'remove_keyboard' => true
														],
													]
												)
													->then(function (message $message) use ($context) {
														// Sended the message

														// Ending the conversation process
														$context->endConversation();
													});
											}
										});
									});
							} else {
								// Not found started search process

								// Sending the message
								$context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_started'] . '*')
									->then(function (message $message) use ($context) {
										// Sended the message

										// Ending the conversation process
										$context->endConversation();

										// Sending the system questions menu
										commands::system_questions($context);
									});
							}
						});
				} else {
					// Not initialized localization

					// Sending the message
					$context->sendMessage('⚠️ *Failed to initialize localization*')
						->then(function (message $message) use ($context) {
							// Sended the message

							// Ending the conversation process
							$context->endConversation();
						});
				}
			} else {
				// Not initialized language

				// Sending the message
				$context->sendMessage('⚠️ *Failed to initialize language*')
					->then(function (message $message) use ($context) {
						// Sended the message

						// Ending the conversation process
						$context->endConversation();
					});
			}
		} else {
			// Not initialized the account

			// Sending the message
			$context->sendMessage('⚠️ *Failed to initialize the account*')
				->then(function (message $message) use ($context) {
					// Sended the message

					// Ending the conversation process
					$context->endConversation();
				});
		}
	}

	/**
	 * Next
	 *
	 * Write actual page + 1 into the question search buffer
	 *
	 * @param context $context Request data from Telegram
	 *
	 * @return void
	 */
	public static function next(context $context): void
	{
		// Initializing the account
		$account = $context->get('account');

		if ($account instanceof record) {
			// Initialized the account

			// Initializing localization 
			$localization = $context->get('localization');

			if ($localization) {
				// Initialized localization

				// Reading from the telegram user buffer
				$context->getUserDataItem(static::PROCESS)
					->then(function ($search) use ($context, $localization) {
						// Readed from the telegram user buffer

						if ($search) {
							// Found started search process

							// Writing into the question search process buffer
							++$search['page'];

							// Writing to the telegram user buffer
							$context->setUserDataItem(static::PROCESS, $search)
								->then(function () use ($context) {
									// Writed to the telegram user buffer

									// Searching
									static::search($context);
								});
						} else {
							// Not found started search process

							// Sending the message
							$context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_started'] . '*')
								->then(function (message $message) use ($context) {
									// Sended the message

									// Ending the conversation process
									$context->endConversation();

									// Sending the system questions menu
									commands::system_questions($context);
								});
						}
					});
			} else {
				// Not initialized localization

				// Sending the message
				$context->sendMessage('⚠️ *Failed to initialize localization*')
					->then(function (message $message) use ($context) {
						// Sended the message

						// Ending the conversation process
						$context->endConversation();
					});
			}
		} else {
			// Not initialized the account

			// Sending the message
			$context->sendMessage('⚠️ *Failed to initialize your Telegram account*')
				->then(function (message $message) use ($context) {
					// Sended the message

					// Ending the conversation process
					$context->endConversation();
				});
		}
	}

	/**
	 * Identifier
	 *
	 * Write identifier into the question search buffer
	 *
	 * @param context $context Request data from Telegram
	 *
	 * @return void
	 */
	public static function identifier(context $context): void
	{
		// Initializing the account
		$account = $context->get('account');

		if ($account instanceof record) {
			// Initialized the account

			// Initializing localization 
			$localization = $context->get('localization');

			if ($localization) {
				// Initialized localization

				// Reading from the telegram user buffer
				$context->getUserDataItem(static::PROCESS)
					->then(function ($search) use ($context, $localization) {
						// Readed from the telegram user buffer

						if ($search) {
							// Found started search process

							// Initializing the button
							$button = $context->getCallbackQuery()?->getData();

							if ($button === 'cancel') {
								// Cancel

								// Sending the message
								$context->sendMessage('❎ *' . $localization[static::PROCESS . '_identifier_cancel_success'] . '*')
									->then(function (message $message) use ($context) {
										// Sended the message

										// Ending the conversation process
										$context->endConversation();

										// Searching
										static::search($context);
									});
							} else if ($button === 'delete') {
								// Delete 

								// Writing into the question search process buffer
								$search['identifier'] = null;

								// Writing to the telegram user buffer
								$context->setUserDataItem(static::PROCESS, $search)
									->then(function () use ($context, $localization) {
										// Writed to the telegram user buffer

										// Sending the message
										$context->sendMessage('🗑 *' . $localization[static::PROCESS . '_identifier_delete_success'] . '*')
											->then(function (message $message) use ($context) {
												// Sended the message

												// Ending the conversation process
												$context->endConversation();

												// Searching
												static::search($context);
											});
									});
							} else {
								// Write

								// Initializing the new identifier
								$new = $context->getMessage()->getText();

								if (!empty($new)) {
									// Initialized the new identifier

									if (mb_strlen($new) >= 1) {
										// Passed minimum length check

										if (mb_strlen($new) <= 12) {
											// Passed maximum length check

											// Search for restricted characters
											preg_match_all('/[^\d]/u', $new, $matches);

											// Declaring the buffer of found restricted characters
											$characters = [];

											foreach ($matches[0] as $match) {
												// Iterating over found restricted characters 

												// Writing into the buffer of found restricted characers
												$characters[] = $match;
											}

											if (empty($characters)) {
												// Not found restricted characters

												// Initializing the old identifier
												$old = empty($search['identifier']) ? '_' . $localization['empty'] . '_' : $search['identifier'];

												// Writing into the question search process buffer
												$search['identifier'] = (int) $new;

												// Writing to the telegram user buffer
												$context->setUserDataItem(static::PROCESS, $search)
													->then(function () use ($context, $localization, $new, $old) {
														// Writed to the telegram user buffer

														// Sending the message
														$context->sendMessage('✅ *' . $localization[static::PROCESS . '_identifier_update_success'] . "* $old → *$new*")
															->then(function (message $message) use ($context) {
																// Sended the message

																// Searching
																static::search($context);
															});
													});
											} else {
												// Found restricted characters

												// Initializing title of the message
												$title = '⚠️  *' . $localization[static::PROCESS . '_identifier_request_restricted_characters_title'] . '*';

												// Initializing description of the message
												$description = '*' . $localization[static::PROCESS . '_identifier_request_restricted_characters_description'] . '* \\' . implode(', \\', $characters);

												// Sending the message
												$context->sendMessage(
													<<<TXT
												$title

												$description
												TXT
												)->then(function (message $message) use ($context) {
													// Sended the message

													// Ending the conversation process
													$context->endConversation();

													// Requesting to enter identifier again
													buttons_question_search::identifier($context);
												});
											}
										} else {
											// Not passed maximum length check

											// Sending the message
											$context->sendMessage('⚠️  *' . $localization[static::PROCESS . '_identifier_request_too_long'] . '*')
												->then(function (message $message) use ($context) {
													// Sended the message

													// Ending the conversation process
													$context->endConversation();

													// Requesting to enter identifier again
													buttons_question_search::identifier($context);
												});
										}
									} else {
										// Not passed minimum length check

										// Sending the message
										$context->sendMessage('⚠️  *' . $localization[static::PROCESS . '_identifier_request_too_short'] . '*')
											->then(function (message $message) use ($context) {
												// Sended the message

												// Ending the conversation process
												$context->endConversation();

												// Requesting to enter identifier again
												buttons_question_search::identifier($context);
											});
									}
								} else {
									// Failed to initialize the new identifier

									// Sending the message
									$context->sendMessage('📄 *' . $localization[static::PROCESS . '_identifier_request_not_acceptable'] . '*')
										->then(function (message  $message) use ($context) {
											// Sended the message

											// Ending the conversation process
											$context->endConversation();

											// Requesting to enter identifier again
											buttons_question_search::identifier($context);
										});
								}
							}
						} else {
							// Not found started search process

							// Sending the message
							$context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_started'] . '*')
								->then(function (message $message) use ($context) {
									// Sended the message

									// Ending the conversation process
									$context->endConversation();

									// Sending the system questions menu
									commands::system_questions($context);
								});
						}
					});
			} else {
				// Not initialized localization

				// Sending the message
				$context->sendMessage('⚠️ *Failed to initialize localization*')
					->then(function (message $message) use ($context) {
						// Sended the message

						// Ending the conversation process
						$context->endConversation();
					});
			}
		} else {
			// Not initialized the account

			// Sending the message
			$context->sendMessage('⚠️ *Failed to initialize your Telegram account*')
				->then(function (message $message) use ($context) {
					// Sended the message

					// Ending the conversation process
					$context->endConversation();
				});
		}
	}

	/**
	 * Text
	 *
	 * Write text into the question search buffer
	 *
	 * @param context $context Request data from Telegram
	 *
	 * @return void
	 */
	public static function text(context $context): void
	{
		// Initializing the account
		$account = $context->get('account');

		if ($account instanceof record) {
			// Initialized the account

			// Initializing localization 
			$localization = $context->get('localization');

			if ($localization) {
				// Initialized localization

				// Reading from the telegram user buffer
				$context->getUserDataItem(static::PROCESS)
					->then(function ($search) use ($context, $localization) {
						// Readed from the telegram user buffer

						if ($search) {
							// Found started search process

							// Initializing the button
							$button = $context->getCallbackQuery()?->getData();

							if ($button === 'cancel') {
								// Cancel

								// Sending the message
								$context->sendMessage('❎ *' . $localization[static::PROCESS . '_text_cancel_success'] . '*')
									->then(function (message $message) use ($context) {
										// Sended the message

										// Ending the conversation process
										$context->endConversation();

										// Searching
										static::search($context);
									});
							} else if ($button === 'delete') {
								// Delete 

								// Writing into the question search process buffer
								$search['text'] = null;

								// Writing to the telegram user buffer
								$context->setUserDataItem(static::PROCESS, $search)
									->then(function () use ($context, $localization) {
										// Writed to the telegram user buffer

										// Sending the message
										$context->sendMessage('🗑 *' . $localization[static::PROCESS . '_text_delete_success'] . '*')
											->then(function (message $message) use ($context) {
												// Sended the message

												// Ending the conversation process
												$context->endConversation();

												// Searching
												static::search($context);
											});
									});
							} else {
								// Write

								// Initializing the new text
								$new = $context->getMessage()->getText();

								if (!empty($new)) {
									// Initialized the new text

									if (mb_strlen($new) >= 3) {
										// Passed minimum length check

										if (mb_strlen($new) <= 256) {
											// Passed maximum length check

											// Initializing the old text
											$old = empty($search['text']) ? '_' . $localization['empty'] . '_' : $search['text'];

											// Writing into the question search process buffer
											$search['text'] = $new;

											// Writing to the telegram user buffer
											$context->setUserDataItem(static::PROCESS, $search)
												->then(function () use ($context, $localization, $new, $old) {
													// Writed to the telegram user buffer

													// Sending the message
													$context->sendMessage('✅ *' . $localization[static::PROCESS . '_text_update_success'] . "* $old → *" . escape::markdown($new) . '*')
														->then(function (message $message) use ($context) {
															// Sended the message

															// Searching
															static::search($context);
														});
												});
										} else {
											// Not passed maximum length check

											// Sending the message
											$context->sendMessage('⚠️  *' . $localization[static::PROCESS . '_text_request_too_long'] . '*')
												->then(function (message $message) use ($context) {
													// Sended the message

													// Ending the conversation process
													$context->endConversation();

													// Requesting to enter text again
													buttons_question_search::text($context);
												});
										}
									} else {
										// Not passed minimum length check

										// Sending the message
										$context->sendMessage('⚠️  *' . $localization[static::PROCESS . '_text_request_too_short'] . '*')
											->then(function (message $message) use ($context) {
												// Sended the message

												// Ending the conversation process
												$context->endConversation();

												// Requesting to enter text again
												buttons_question_search::text($context);
											});
									}
								} else {
									// Failed to initialize the new text

									// Sending the message
									$context->sendMessage('📄 *' . $localization[static::PROCESS . '_text_request_not_acceptable'] . '*')
										->then(function (message  $message) use ($context) {
											// Sended the message

											// Ending the conversation process
											$context->endConversation();

											// Requesting to enter text again
											buttons_question_search::text($context);
										});
								}
							}
						} else {
							// Not found started search process

							// Sending the message
							$context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_started'] . '*')
								->then(function (message $message) use ($context) {
									// Sended the message

									// Ending the conversation process
									$context->endConversation();

									// Sending the system questions menu
									commands::system_questions($context);
								});
						}
					});
			} else {
				// Not initialized localization

				// Sending the message
				$context->sendMessage('⚠️ *Failed to initialize localization*')
					->then(function (message $message) use ($context) {
						// Sended the message

						// Ending the conversation process
						$context->endConversation();
					});
			}
		} else {
			// Not initialized the account

			// Sending the message
			$context->sendMessage('⚠️ *Failed to initialize your Telegram account*')
				->then(function (message $message) use ($context) {
					// Sended the message

					// Ending the conversation process
					$context->endConversation();
				});
		}
	}
	/**
	 * A
	 *
	 * Write A-answer into the question search buffer
	 *
	 * @param context $context Request data from Telegram
	 *
	 * @return void
	 */
	public static function a(context $context): void
	{
		// Initializing the account
		$account = $context->get('account');

		if ($account instanceof record) {
			// Initialized the account

			// Initializing localization 
			$localization = $context->get('localization');

			if ($localization) {
				// Initialized localization

				// Reading from the telegram user buffer
				$context->getUserDataItem(static::PROCESS)
					->then(function ($search) use ($context, $localization) {
						// Readed from the telegram user buffer

						if ($search) {
							// Found started search process

							// Initializing the button
							$button = $context->getCallbackQuery()?->getData();

							if ($button === 'cancel') {
								// Cancel

								// Sending the message
								$context->sendMessage('❎ *' . $localization[static::PROCESS . '_a_cancel_success'] . '*')
									->then(function (message $message) use ($context) {
										// Sended the message

										// Ending the conversation process
										$context->endConversation();

										// Searching
										static::search($context);
									});
							} else if ($button === 'delete') {
								// Delete 

								// Writing into the question search process buffer
								$search['A'] = null;

								// Writing to the telegram user buffer
								$context->setUserDataItem(static::PROCESS, $search)
									->then(function () use ($context, $localization) {
										// Writed to the telegram user buffer

										// Sending the message
										$context->sendMessage('🗑 *' . $localization[static::PROCESS . '_a_delete_success'] . '*')
											->then(function (message $message) use ($context) {
												// Sended the message

												// Ending the conversation process
												$context->endConversation();

												// Searching
												static::search($context);
											});
									});
							} else {
								// Write

								// Initializing the new A-answer
								$new = $context->getMessage()->getText();

								if (!empty($new)) {
									// Initialized the new A-answer

									if (mb_strlen($new) >= 3) {
										// Passed minimum length check

										if (mb_strlen($new) <= 128) {
											// Passed maximum length check

											// Initializing the old A-answer
											$old = empty($search['A']) ? '_' . $localization['empty'] . '_' : $search['A'];

											// Writing into the question search process buffer
											$search['A'] = $new;

											// Writing to the telegram user buffer
											$context->setUserDataItem(static::PROCESS, $search)
												->then(function () use ($context, $localization, $new, $old) {
													// Writed to the telegram user buffer

													// Sending the message
													$context->sendMessage('✅ *' . $localization[static::PROCESS . '_a_update_success'] . "* $old → *" . escape::markdown($new) . '*')
														->then(function (message $message) use ($context) {
															// Sended the message

															// Searching
															static::search($context);
														});
												});
										} else {
											// Not passed maximum length check

											// Sending the message
											$context->sendMessage('⚠️  *' . $localization[static::PROCESS . '_a_request_too_long'] . '*')
												->then(function (message $message) use ($context) {
													// Sended the message

													// Ending the conversation process
													$context->endConversation();

													// Requesting to enter A-answer again
													buttons_question_search::a($context);
												});
										}
									} else {
										// Not passed minimum length check

										// Sending the message
										$context->sendMessage('⚠️  *' . $localization[static::PROCESS . '_a_request_too_short'] . '*')
											->then(function (message $message) use ($context) {
												// Sended the message

												// Ending the conversation process
												$context->endConversation();

												// Requesting to enter A-answer again
												buttons_question_search::a($context);
											});
									}
								} else {
									// Failed to initialize the new A-answer

									// Sending the message
									$context->sendMessage('📄 *' . $localization[static::PROCESS . '_a_request_not_acceptable'] . '*')
										->then(function (message  $message) use ($context) {
											// Sended the message

											// Ending the conversation process
											$context->endConversation();

											// Requesting to enter A-answer again
											buttons_question_search::a($context);
										});
								}
							}
						} else {
							// Not found started search process

							// Sending the message
							$context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_started'] . '*')
								->then(function (message $message) use ($context) {
									// Sended the message

									// Ending the conversation process
									$context->endConversation();

									// Sending the system questions menu
									commands::system_questions($context);
								});
						}
					});
			} else {
				// Not initialized localization

				// Sending the message
				$context->sendMessage('⚠️ *Failed to initialize localization*')
					->then(function (message $message) use ($context) {
						// Sended the message

						// Ending the conversation process
						$context->endConversation();
					});
			}
		} else {
			// Not initialized the account

			// Sending the message
			$context->sendMessage('⚠️ *Failed to initialize your Telegram account*')
				->then(function (message $message) use ($context) {
					// Sended the message

					// Ending the conversation process
					$context->endConversation();
				});
		}
	}


	/**
	 * B
	 *
	 * Write B-answer into the question search buffer
	 *
	 * @param context $context Request data from Telegram
	 *
	 * @return void
	 */
	public static function b(context $context): void
	{
		// Initializing the account
		$account = $context->get('account');

		if ($account instanceof record) {
			// Initialized the account

			// Initializing localization 
			$localization = $context->get('localization');

			if ($localization) {
				// Initialized localization

				// Reading from the telegram user buffer
				$context->getUserDataItem(static::PROCESS)
					->then(function ($search) use ($context, $localization) {
						// Readed from the telegram user buffer

						if ($search) {
							// Found started search process

							// Initializing the button
							$button = $context->getCallbackQuery()?->getData();

							if ($button === 'cancel') {
								// Cancel

								// Sending the message
								$context->sendMessage('❎ *' . $localization[static::PROCESS . '_b_cancel_success'] . '*')
									->then(function (message $message) use ($context) {
										// Sended the message

										// Ending the conversation process
										$context->endConversation();

										// Searching
										static::search($context);
									});
							} else if ($button === 'delete') {
								// Delete 

								// Writing into the question search process buffer
								$search['B'] = null;

								// Writing to the telegram user buffer
								$context->setUserDataItem(static::PROCESS, $search)
									->then(function () use ($context, $localization) {
										// Writed to the telegram user buffer

										// Sending the message
										$context->sendMessage('🗑 *' . $localization[static::PROCESS . '_b_delete_success'] . '*')
											->then(function (message $message) use ($context) {
												// Sended the message

												// Ending the conversation process
												$context->endConversation();

												// Searching
												static::search($context);
											});
									});
							} else {
								// Write

								// Initializing the new B-answer
								$new = $context->getMessage()->getText();

								if (!empty($new)) {
									// Initialized the new B-snswer

									if (mb_strlen($new) >= 3) {
										// Passed minimum length check

										if (mb_strlen($new) <= 128) {
											// Passed maximum length check

											// Initializing the old B-answer
											$old = empty($search['B']) ? '_' . $localization['empty'] . '_' : $search['B'];

											// Writing into the question search process buffer
											$search['B'] = $new;

											// Writing to the telegram user buffer
											$context->setUserDataItem(static::PROCESS, $search)
												->then(function () use ($context, $localization, $new, $old) {
													// Writed to the telegram user buffer

													// Sending the message
													$context->sendMessage('✅ *' . $localization[static::PROCESS . '_b_update_success'] . "* $old → *" . escape::markdown($new) . '*')
														->then(function (message $message) use ($context) {
															// Sended the message

															// Searching
															static::search($context);
														});
												});
										} else {
											// Not passed maximum length check

											// Sending the message
											$context->sendMessage('⚠️  *' . $localization[static::PROCESS . '_b_request_too_long'] . '*')
												->then(function (message $message) use ($context) {
													// Sended the message

													// Ending the conversation process
													$context->endConversation();

													// Requesting to enter B-answer again
													buttons_question_search::b($context);
												});
										}
									} else {
										// Not passed minimum length check

										// Sending the message
										$context->sendMessage('⚠️  *' . $localization[static::PROCESS . '_b_request_too_short'] . '*')
											->then(function (message $message) use ($context) {
												// Sended the message

												// Ending the conversation process
												$context->endConversation();

												// Requesting to enter B-answer again
												buttons_question_search::b($context);
											});
									}
								} else {
									// Failed to initialize the new B-answer

									// Sending the message
									$context->sendMessage('📄 *' . $localization[static::PROCESS . '_b_request_not_acceptable'] . '*')
										->then(function (message  $message) use ($context) {
											// Sended the message

											// Ending the conversation process
											$context->endConversation();

											// Requesting to enter B-answer again
											buttons_question_search::b($context);
										});
								}
							}
						} else {
							// Not found started search process

							// Sending the message
							$context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_started'] . '*')
								->then(function (message $message) use ($context) {
									// Sended the message

									// Ending the conversation process
									$context->endConversation();

									// Sending the system questions menu
									commands::system_questions($context);
								});
						}
					});
			} else {
				// Not initialized localization

				// Sending the message
				$context->sendMessage('⚠️ *Failed to initialize localization*')
					->then(function (message $message) use ($context) {
						// Sended the message

						// Ending the conversation process
						$context->endConversation();
					});
			}
		} else {
			// Not initialized the account

			// Sending the message
			$context->sendMessage('⚠️ *Failed to initialize your Telegram account*')
				->then(function (message $message) use ($context) {
					// Sended the message

					// Ending the conversation process
					$context->endConversation();
				});
		}
	}

	/**
	 * C
	 *
	 * Write C-answer into the question search buffer
	 *
	 * @param context $context Request data from Telegram
	 *
	 * @return void
	 */
	public static function c(context $context): void
	{
		// Initializing the account
		$account = $context->get('account');

		if ($account instanceof record) {
			// Initialized the account

			// Initializing localization 
			$localization = $context->get('localization');

			if ($localization) {
				// Initialized localization

				// Reading from the telegram user buffer
				$context->getUserDataItem(static::PROCESS)
					->then(function ($search) use ($context, $localization) {
						// Readed from the telegram user buffer

						if ($search) {
							// Found started search process

							// Initializing the button
							$button = $context->getCallbackQuery()?->getData();

							if ($button === 'cancel') {
								// Cancel

								// Sending the message
								$context->sendMessage('❎ *' . $localization[static::PROCESS . '_c_cancel_success'] . '*')
									->then(function (message $message) use ($context) {
										// Sended the message

										// Ending the conversation process
										$context->endConversation();

										// Searching
										static::search($context);
									});
							} else if ($button === 'delete') {
								// Delete 

								// Writing into the question search process buffer
								$search['C'] = null;

								// Writing to the telegram user buffer
								$context->setUserDataItem(static::PROCESS, $search)
									->then(function () use ($context, $localization) {
										// Writed to the telegram user buffer

										// Sending the message
										$context->sendMessage('🗑 *' . $localization[static::PROCESS . '_c_delete_success'] . '*')
											->then(function (message $message) use ($context) {
												// Sended the message

												// Ending the conversation process
												$context->endConversation();

												// Searching
												static::search($context);
											});
									});
							} else {
								// Write

								// Initializing the new C-answer
								$new = $context->getMessage()->getText();

								if (!empty($new)) {
									// Initialized the new C-answer

									if (mb_strlen($new) >= 3) {
										// Passed minimum length check

										if (mb_strlen($new) <= 128) {
											// Passed maximum length check

											// Initializing the old C-answer
											$old = empty($search['C']) ? '_' . $localization['empty'] . '_' : $search['C'];

											// Writing into the question search process buffer
											$search['C'] = $new;

											// Writing to the telegram user buffer
											$context->setUserDataItem(static::PROCESS, $search)
												->then(function () use ($context, $localization, $new, $old) {
													// Writed to the telegram user buffer

													// Sending the message
													$context->sendMessage('✅ *' . $localization[static::PROCESS . '_c_update_success'] . "* $old → *" . escape::markdown($new) . '*')
														->then(function (message $message) use ($context) {
															// Sended the message

															// Searching
															static::search($context);
														});
												});
										} else {
											// Not passed maximum length check

											// Sending the message
											$context->sendMessage('⚠️  *' . $localization[static::PROCESS . '_c_request_too_long'] . '*')
												->then(function (message $message) use ($context) {
													// Sended the message

													// Ending the conversation process
													$context->endConversation();

													// Requesting to enter C-answer again
													buttons_question_search::c($context);
												});
										}
									} else {
										// Not passed minimum length check

										// Sending the message
										$context->sendMessage('⚠️  *' . $localization[static::PROCESS . '_c_request_too_short'] . '*')
											->then(function (message $message) use ($context) {
												// Sended the message

												// Ending the conversation process
												$context->endConversation();

												// Requesting to enter C-answer again
												buttons_question_search::c($context);
											});
									}
								} else {
									// Failed to initialize the new text

									// Sending the message
									$context->sendMessage('📄 *' . $localization[static::PROCESS . '_c_request_not_acceptable'] . '*')
										->then(function (message  $message) use ($context) {
											// Sended the message

											// Ending the conversation process
											$context->endConversation();

											// Requesting to enter C-answer again
											buttons_question_search::c($context);
										});
								}
							}
						} else {
							// Not found started search process

							// Sending the message
							$context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_started'] . '*')
								->then(function (message $message) use ($context) {
									// Sended the message

									// Ending the conversation process
									$context->endConversation();

									// Sending the system questions menu
									commands::system_questions($context);
								});
						}
					});
			} else {
				// Not initialized localization

				// Sending the message
				$context->sendMessage('⚠️ *Failed to initialize localization*')
					->then(function (message $message) use ($context) {
						// Sended the message

						// Ending the conversation process
						$context->endConversation();
					});
			}
		} else {
			// Not initialized the account

			// Sending the message
			$context->sendMessage('⚠️ *Failed to initialize your Telegram account*')
				->then(function (message $message) use ($context) {
					// Sended the message

					// Ending the conversation process
					$context->endConversation();
				});
		}
	}

	/**
	 * D
	 *
	 * Write D-answer into the question search buffer
	 *
	 * @param context $context Request data from Telegram
	 *
	 * @return void
	 */
	public static function d(context $context): void
	{
		// Initializing the account
		$account = $context->get('account');

		if ($account instanceof record) {
			// Initialized the account

			// Initializing localization 
			$localization = $context->get('localization');

			if ($localization) {
				// Initialized localization

				// Reading from the telegram user buffer
				$context->getUserDataItem(static::PROCESS)
					->then(function ($search) use ($context, $localization) {
						// Readed from the telegram user buffer

						if ($search) {
							// Found started search process

							// Initializing the button
							$button = $context->getCallbackQuery()?->getData();

							if ($button === 'cancel') {
								// Cancel

								// Sending the message
								$context->sendMessage('❎ *' . $localization[static::PROCESS . '_d_cancel_success'] . '*')
									->then(function (message $message) use ($context) {
										// Sended the message

										// Ending the conversation process
										$context->endConversation();

										// Searching
										static::search($context);
									});
							} else if ($button === 'delete') {
								// Delete 

								// Writing into the question search process buffer
								$search['D'] = null;

								// Writing to the telegram user buffer
								$context->setUserDataItem(static::PROCESS, $search)
									->then(function () use ($context, $localization) {
										// Writed to the telegram user buffer

										// Sending the message
										$context->sendMessage('🗑 *' . $localization[static::PROCESS . '_d_delete_success'] . '*')
											->then(function (message $message) use ($context) {
												// Sended the message

												// Ending the conversation process
												$context->endConversation();

												// Searching
												static::search($context);
											});
									});
							} else {
								// Write

								// Initializing the new D-answer
								$new = $context->getMessage()->getText();

								if (!empty($new)) {
									// Initialized the new D-answer

									if (mb_strlen($new) >= 3) {
										// Passed minimum length check

										if (mb_strlen($new) <= 128) {
											// Passed maximum length check

											// Initializing the old D-answer
											$old = empty($search['D']) ? '_' . $localization['empty'] . '_' : $search['D'];

											// Writing into the question search process buffer
											$search['D'] = $new;

											// Writing to the telegram user buffer
											$context->setUserDataItem(static::PROCESS, $search)
												->then(function () use ($context, $localization, $new, $old) {
													// Writed to the telegram user buffer

													// Sending the message
													$context->sendMessage('✅ *' . $localization[static::PROCESS . '_d_update_success'] . "* $old → *" . escape::markdown($new) . '*')
														->then(function (message $message) use ($context) {
															// Sended the message

															// Searching
															static::search($context);
														});
												});
										} else {
											// Not passed maximum length check

											// Sending the message
											$context->sendMessage('⚠️  *' . $localization[static::PROCESS . '_d_request_too_long'] . '*')
												->then(function (message $message) use ($context) {
													// Sended the message

													// Ending the conversation process
													$context->endConversation();

													// Requesting to enter D-answer again
													buttons_question_search::d($context);
												});
										}
									} else {
										// Not passed minimum length check

										// Sending the message
										$context->sendMessage('⚠️  *' . $localization[static::PROCESS . '_d_request_too_short'] . '*')
											->then(function (message $message) use ($context) {
												// Sended the message

												// Ending the conversation process
												$context->endConversation();

												// Requesting to enter D-answer again
												buttons_question_search::d($context);
											});
									}
								} else {
									// Failed to initialize the new D-answer

									// Sending the message
									$context->sendMessage('📄 *' . $localization[static::PROCESS . '_d_request_not_acceptable'] . '*')
										->then(function (message  $message) use ($context) {
											// Sended the message

											// Ending the conversation process
											$context->endConversation();

											// Requesting to enter D-answer again
											buttons_question_search::d($context);
										});
								}
							}
						} else {
							// Not found started search process

							// Sending the message
							$context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_started'] . '*')
								->then(function (message $message) use ($context) {
									// Sended the message

									// Ending the conversation process
									$context->endConversation();

									// Sending the system questions menu
									commands::system_questions($context);
								});
						}
					});
			} else {
				// Not initialized localization

				// Sending the message
				$context->sendMessage('⚠️ *Failed to initialize localization*')
					->then(function (message $message) use ($context) {
						// Sended the message

						// Ending the conversation process
						$context->endConversation();
					});
			}
		} else {
			// Not initialized the account

			// Sending the message
			$context->sendMessage('⚠️ *Failed to initialize your Telegram account*')
				->then(function (message $message) use ($context) {
					// Sended the message

					// Ending the conversation process
					$context->endConversation();
				});
		}
	}

	/**
	 * Keyboard
	 *
	 * Generate inline keyboard
	 *
	 * @param record $question The question
	 * @param array $localization The account localization
	 *
	 * @return array Generated inline keyboard
	 */
	public static function keyboard(record $question, array $localization): array
	{
		// Declaring the toggle button
		$toggle = [];

		if ($question->active) {
			// Active

			// Initializing the toggle button
			$toggle = [
				'text' => '🟢 ' . $localization[static::PROCESS . '_button_active'],
				'callback_data' => static::PROCESS . '_deactivate'
			];
		} else {
			// Inactive

			// Initializing the toggle button
			$toggle = [
				'text' => '🔴 ' . $localization[static::PROCESS . '_button_inactive'],
				'callback_data' => static::PROCESS . '_activate'
			];
		}

		// Exit (success)
		return [
			[
				[
					'text' => '🗑 ' . $localization[static::PROCESS . '_button_delete'],
					'callback_data' => static::PROCESS . '_delete'
				],
				[
					'text' => '🐣 ' . $localization[static::PROCESS . '_button_author'],
					'callback_data' => static::PROCESS . '_author'
				],
				$toggle
			],
			[
				[
					'text' => '🔏 ' . $localization[static::PROCESS . '_button_answer'],
					'callback_data' => static::PROCESS . '_answer'
				],
				[
					'text' => '🌏 ' . $localization[static::PROCESS . '_button_localizations'],
					'callback_data' => static::PROCESS . '_localizations'
				],
			]
		];
	}

	/**
	 * Message text
	 *
	 * Generate text
	 *
	 * @param record $question The question
	 * @param array $localization The account localization
	 *
	 * @return string Generated text
	 */
	public static function message(record $question, array $localization): string
	{
		// Initializing the answer model
		$model_answer = new answer();

		// Initializing the answer
		$answer = $model_answer->database->read(
			filter: fn(record $record) => $record->identifier === $question->identifier,
			amount: 1
		)[0] ?? null;

		// Declaring the questions list
		$list = '';

		foreach (language::cases() as $case) {
			// Iterating over language

			// Initializing the localization model by the language
			$model_question_localization = new question_localization(language: $case);

			// Initializing the localization
			$_localization = $model_question_localization->database->read(
				filter: fn(record $record) => $record->identifier === $question->identifier,
				amount: 1
			)[0] ?? null;

			// Writing into the questions list
			$list .= PHP_EOL . $case->flag() . ' *' . $case->label(language::{$account->language ?? 'en'} ?? language::en) . ':* ' . ($localization[$_localization instanceof record ? 'yes' : 'no']);
		}

		// Deinitializing unnecessary variables
		unset($case, $model_question, $model_question_localization, $model_answer, $amount);		// Exit (success)
		return sprintf(
			<<<TXT
			📄 *%s \#%u* 

			🔏 *%s:* %s
			%s
			TXT,
			$localization[static::PROCESS . '_question_title'],
			$question->identifier,
			$localization[static::PROCESS . '_question_answer'],
			$answer instanceof record ? "A:$answer->a B:$answer->b C:$answer->c D:$answer->d" : $localization['empty'],
			$list
		);
	}
}
