<?php

namespace routes;

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

class economicPaymentTermsRoute
{
    use route_t;

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


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