<?php

namespace App\Traits;

use CodeIgniter\Session\Session;

trait AuthTrait
{
    final protected function session_AuthTrait(): Session
    {
        $session = \Config\Services::session();
        $session->set(SESSION_NAMES['ISLOGIN'], false);
        $session->set('currentRoles', [DEFAULTS["ROLE"]]);
        if ($session->get(SESSION_NAMES['ISLOGIN'])) {
            $session->set(SESSION_NAMES['ISLOGIN'], true);
            $session->set(
                'currentRoles',
                explode(
                    DEFAULTS['DELIMITER_ROLE'],
                    $session->get(SESSION_NAMES['AUTH'])[AUTH_FIELDS['ROLE']]
                )
            );
        }
        return $session;
    }
}
