<?php

declare(strict_types=1);

namespace mirzaev\huesos;

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

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

// Версия робота
define('ROBOT_VERSION', '1.0.0');
define('VIEWS', realpath('..' . DIRECTORY_SEPARATOR . 'views'));
define('STORAGE', realpath('..' . DIRECTORY_SEPARATOR . 'storage'));
define('SETTINGS', realpath('..' . DIRECTORY_SEPARATOR . 'settings'));
define('INDEX', __DIR__);
define('ROOT',  INDEX . DIRECTORY_SEPARATOR	. '..' . DIRECTORY_SEPARATOR	. '..' . DIRECTORY_SEPARATOR	. '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR);
define('THEME', 'default');

define('CDEK', require(SETTINGS . DIRECTORY_SEPARATOR . 'deliveries' . DIRECTORY_SEPARATOR . 'cdek.php'));

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

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

// Initializing routes
$core->router
	->write('/', new route('catalog', 'index', 'catalog'), 'GET')
	->write('/offer', new route('index', 'offer'), 'GET')
	->write('/cart', new route('cart', 'index', 'cart'), 'GET')
	->write('/cart/product', new route('cart', 'product', 'cart'), 'PATCH')
	->write('/cart/summary', new route('cart', 'summary', 'cart'), 'GET')
	/* ->write('/cart/share', new route('cart', 'share', 'cart'), 'POST') */
	->write('/cart/share', new route('cart', 'share', 'cart'), 'POST')
	->write('/order/robokassa', new route('cart', 'robokassa', 'cart'), 'GET')
	->write('/account/write', new route('account', 'write', 'account'), 'PATCH')
	->write('/session/write', new route('session', 'write', 'session'), 'PATCH')
	->write('/session/connect/telegram', new route('session', 'telegram', 'session'), 'PUT')
	->write('/delivery/write', new route('delivery', 'write', 'delivery'), 'PATCH')
	->write('/delivery/calculate', new route('delivery', 'calculate', 'delivery'), 'GET');

// Handling request
$core->start();
