<?php

declare(strict_types=1);

namespace kodorvan\surikov;

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

error_reporting(E_ALL);

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

// 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 the storage 
define('STORAGE', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'storage');

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

// Initializing the database connection parameters
define('DATABASE', require(SETTINGS . DIRECTORY_SEPARATOR . 'database.php'));

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

// Initializing the core
$core = new core(
	namespace: __NAMESPACE__
);

// Initializing routes
$core->router
	// ->write('/', new route('index', 'index'), 'GET')

	->write('/', new route('publications', 'index'), 'GET')
	
	->write('/publications/delete/$identifier', new route('publications', 'delete'), 'POST')
	->write('/publications/write', new route('publications', 'write'), 'POST')
	->write('/publications/update/$identifier', new route('publications', 'update'), 'POST')
	->write('/storage/publications/$identifier', new route('publications', 'read'), 'GET')

	->write('/account/registration', new route('accounts', 'registration'), 'POST')
	->write('/account/authentication', new route('accounts', 'authentication'), 'POST')
	->write('/account/deauthentication', new route('accounts', 'deauthentication'), 'POST')
	->write('/account/deauthentication', new route('accounts', 'deauthentication'), 'GET')

	->write('/books', new route('books', 'index'), 'GET')
	->write('/books/$identifier', new route('books', 'index'), 'GET')
	->write('/books/$identifier/$page', new route('books', 'index'), 'GET')
	->write('/books/$identifier/$page/rotate', new route('books', 'rotate'), 'POST')
	->write('/books/$identifier/delete', new route('books', 'delete'), 'POST')
	->write('/storage/books/$identifier/$page', new route('books', 'read'), 'GET')
	->write('/storage/books/write', new route('books', 'write'), 'POST')

	->write('/kemenov', new route('kemenov', 'index'), 'GET')
	->write('/surikov', new route('surikov', 'index'), 'GET')
	->write('/contacts', new route('contacts', 'index'), 'GET');
;
// Handling the request
$core->start();
