<?php

namespace routes;

use classes\authentication;
use classes\economic;
use classes\response;
use classes\router;
use objects\logs_o;
use traits\route_t;

class economicLayoutsRoute
{
    use route_t;

    public function run(): void
    {
        global /** @var response $response */
        /** @var router $router */
        $router, $response;


        $this->get('/economic/layouts', function () {
            global $response;
            $this->requirePermission('economic_layouts');
            $user = (new authentication())->get_user();
            if ($user) {
                (new logs_o())->add('economic_layouts', 'global', 1, $user->id, 'ECONOMIC_LAYOUTS', 'Successfully fetched economic layouts');
                $response->success(
                    (new economic())->layouts->get()->collection
                );
            } else {
                (new logs_o())->add('economic_layouts', 'global', 1, 0, 'ECONOMIC_LAYOUTS', 'No user found, or invalid session');
                $response->error('Invalid session', 400);
            }
        },
            [
                'economic_layouts' => 'Get economic layouts'
            ]
        );
    }
}