package com.mzh.library.service;

import com.mzh.library.entity.Permission;
import com.mzh.library.entity.Role;

public final class PermissionPolicyCheck {
    private PermissionPolicyCheck() {
    }

    public static void main(String[] args) {
        PermissionPolicy policy = new PermissionPolicy();

        require(policy.allows(Role.ADMINISTRATOR, Permission.MANAGE_USERS), "administrator should manage users");
        require(policy.allows(Role.ADMINISTRATOR, Permission.VIEW_REPORTS), "administrator should view reports");
        require(policy.allows(Role.ADMINISTRATOR, Permission.VIEW_SYSTEM_LOGS), "administrator should view system logs");
        require(policy.allows(Role.LIBRARIAN, Permission.MANAGE_BORROWING), "librarian should manage borrowing");
        require(policy.allows(Role.LIBRARIAN, Permission.MANAGE_READERS), "librarian should manage readers");
        require(policy.allows(Role.LIBRARIAN, Permission.VIEW_REPORTS), "librarian should view reports");
        require(!policy.allows(Role.LIBRARIAN, Permission.VIEW_SYSTEM_LOGS), "librarian should not view system logs");
        require(!policy.allows(Role.LIBRARIAN, Permission.BORROW_BOOKS), "librarian should not borrow as a reader");
        require(!policy.allows(Role.LIBRARIAN, Permission.MANAGE_USERS), "librarian should not manage users");
        require(policy.allows(Role.READER, Permission.VIEW_CATALOG), "reader should view catalog");
        require(policy.allows(Role.READER, Permission.BORROW_BOOKS), "reader should view borrowing capabilities");
        require(!policy.allows(Role.READER, Permission.VIEW_REPORTS), "reader should not view reports");
        require(!policy.allows(Role.READER, Permission.VIEW_SYSTEM_LOGS), "reader should not view system logs");
        require(!policy.allows(Role.READER, Permission.MANAGE_BORROWING), "reader should not manage borrowing");
        require(!policy.allows(Role.READER, Permission.MANAGE_BOOKS), "reader should not manage books");
        require(!policy.allows(Role.READER, Permission.MANAGE_READERS), "reader should not manage readers");
    }

    private static void require(boolean condition, String message) {
        if (!condition) {
            throw new AssertionError(message);
        }
    }
}
