<?php

declare(strict_types=1);

namespace Core;

use App\Models\AdminUser;

abstract class Controller
{
    protected function view(string $view, array $data = [], string $layout = 'app'): void
    {
        View::render($view, $data, $layout);
    }

    protected function redirectTo(string $path): never
    {
        redirect(baseUrl($path));
    }

    protected function requireAdmin(): void
    {
        if (!AdminUser::current()) {
            Session::flash('error', 'Faça login para acessar o painel.');
            redirect(baseUrl('admin/login'));
        }
    }

    protected function requireAdminRole(): void
    {
        $this->requireAdmin();

        if (!AdminUser::currentIsAdmin()) {
            Session::flash('error', 'Apenas administradores podem acessar esta área.');
            redirect(baseUrl('admin/admissoes'));
        }
    }
}
