<?php

declare(strict_types=1);

namespace mirzaev\ebala;

// Файлы проекта
use mirzaev\ebala\controllers\core as controller,
	mirzaev\ebala\models\core as model;

// Фреймворк
use mirzaev\minimal\core,
	mirzaev\minimal\router;

ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);

define('VIEWS', realpath('..' . DIRECTORY_SEPARATOR . 'views'));
define('STORAGE', realpath('..' . DIRECTORY_SEPARATOR . 'storage'));
define('INDEX', __DIR__);

// Автозагрузка
require __DIR__ 
	. DIRECTORY_SEPARATOR . '..'  
	. DIRECTORY_SEPARATOR . '..' 
	. DIRECTORY_SEPARATOR . '..' 
	. DIRECTORY_SEPARATOR . '..' 
	. DIRECTORY_SEPARATOR . 'vendor' 
	. DIRECTORY_SEPARATOR . 'autoload.php';

// Инициализация маршрутазитора
$router = new router;

// Запись маршрутов
$router->write('/', 'index', 'index', 'GET');
$router->write('/', 'index', 'index', 'POST');
$router->write('/entry', 'index', 'entry', 'POST');
$router->write('/worker/$worker/read', 'task', 'worker', 'POST');
$router->write('/worker/$id/fields', 'worker', 'fields', 'POST');
$router->write('/worker/$id/update', 'worker', 'update', 'POST');
$router->write('/worker/$id/fire', 'worker', 'fire', 'POST');
$router->write('/worker/$id/hire', 'worker', 'hire', 'POST');
$router->write('/workers', 'worker', 'index', 'GET');
$router->write('/workers', 'worker', 'index', 'POST');
$router->write('/workers/read', 'worker', 'read', 'POST');
$router->write('/workers/list', 'worker', 'datalist', 'POST');
$router->write('/workers/create', 'worker', 'create', 'POST');
$router->write('/market/$market/read', 'task', 'market', 'POST');
$router->write('/market/$id/fields', 'market', 'fields', 'POST');
$router->write('/market/$id/update', 'market', 'update', 'POST');
$router->write('/markets', 'market', 'index', 'GET');
$router->write('/markets', 'market', 'index', 'POST');
$router->write('/markets/read', 'market', 'read', 'POST');
$router->write('/markets/list', 'market', 'datalist', 'POST');
$router->write('/markets/create', 'market', 'create', 'POST');
$router->write('/operators', 'operator', 'index', 'GET');
$router->write('/operators', 'operator', 'index', 'POST');
$router->write('/operators/read', 'operator', 'read', 'POST');
$router->write('/operators/create', 'operator', 'create', 'POST');
$router->write('/administrators', 'administrator', 'index', 'GET');
$router->write('/administrators', 'administrator', 'index', 'POST');
$router->write('/administrators/read', 'administrator', 'read', 'POST');
$router->write('/administrators/create', 'administrator', 'create', 'POST');
$router->write('/settings', 'settings', 'index', 'GET');
$router->write('/settings', 'settings', 'index', 'POST');
$router->write('/$id', 'account', 'index', 'GET');
$router->write('/$id', 'account', 'index', 'POST');
$router->write('/$id/fields', 'account', 'fields', 'POST');
$router->write('/$id/update', 'account', 'update', 'POST');
$router->write('/$id/delete', 'account', 'delete', 'POST');
$router->write('/$id/ban', 'account', 'ban', 'POST');
$router->write('/$id/unban', 'account', 'unban', 'POST');
$router->write('/session/worker', 'session', 'worker', 'POST');
$router->write('/session/write', 'session', 'write', 'POST');
$router->write('/session/read', 'session', 'read', 'POST');
$router->write('/session/administrator', 'session', 'administrator', 'POST');
$router->write('/session/operator', 'session', 'operator', 'POST');
$router->write('/session/market', 'session', 'market', 'POST');
$router->write('/session/password', 'session', 'password', 'POST');
$router->write('/session/invite', 'session', 'invite', 'POST');
$router->write('/tasks/create', 'task', 'create', 'POST');
$router->write('/tasks/read', 'task', 'read', 'POST');
$router->write('/works/list', 'work', 'datalist', 'POST');
$router->write('/tasks/works', 'task', 'works', 'POST');
$router->write('/task/$task/read', 'task', 'task', 'POST');
$router->write('/task/$task/value', 'task', 'value', 'POST');
$router->write('/task/$task/confirm', 'task', 'confirm', 'POST');
$router->write('/task/$task/problem', 'task', 'problem', 'POST');
$router->write('/task/$task/complete', 'task', 'complete', 'POST');
$router->write('/task/$task/hide', 'task', 'hide', 'POST');
$router->write('/task/$task/remove', 'task', 'remove', 'POST');
$router->write('/task/$task/work', 'task', 'work', 'POST');
$router->write('/task/$task/date', 'task', 'date', 'POST');
$router->write('/task/$task/description', 'task', 'description', 'POST');
$router->write('/task/$task/commentary', 'task', 'commentary', 'POST');
$router->write('/task/$task/worker/update', 'task', 'update', 'POST');
$router->write('/task/$task/market/update', 'task', 'update', 'POST');
$router->write('/task/$task/publish', 'task', 'publish', 'POST');
$router->write('/task/$task/unpublish', 'task', 'unpublish', 'POST');
$router->write('/task/$task/chat', 'task', 'chat', 'POST');
$router->write('/task/$task/chat/send', 'task', 'message', 'POST');
$router->write('/elements/menu', 'index', 'menu', 'POST');
$router->write('/payments/workers', 'payments', 'workers', 'POST');
$router->write('/payments/markets', 'payments', 'markets', 'POST');

// Инициализация ядра
$core = new core(namespace: __NAMESPACE__, router: $router, controller: new controller(false), model: new model(false));


// Обработка запроса
echo $core->start();
