<?php
declare(strict_types=1);

namespace KbMarkdownImporter\Access;

use KbMarkdownImporter\Plugin;

final class AccessController
{
    public function canView(): bool
    {
        $settings = Plugin::settings();

        return '1' === $settings['public_docs'] || is_user_logged_in() || current_user_can('view_kb_docs');
    }

    public function enforce(): void
    {
        if ($this->canView()) {
            return;
        }

        auth_redirect();
    }
}
