<?php

namespace App\Filters;

use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\Filters\FilterInterface;

class GuestFilter implements FilterInterface
{
    public function before(RequestInterface $request, $arguments = null)
    {
        $session = session();

        // Kalau sudah login, arahkan ke dashboard sesuai level
        if ($session->get('isLoggedIn')) {
            switch ($session->get('userroleid')) {
                case 0: return redirect()->to('/superuser');
                case 1: return redirect()->to('/admin');
                case 2: return redirect()->to('/lab');
                case 3: return redirect()->to('/phlebo');
                case 4: return redirect()->to('/cs');
                default: return redirect()->to('/login');
            }
        }
    }

    public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
    {
        // tidak digunakan
    }
}
