package com.mzh.library.entity; import java.util.Locale; public enum Role { ADMINISTRATOR("administrator", "Administrator"), LIBRARIAN("librarian", "Librarian"), READER("reader", "Reader"); private final String code; private final String displayName; Role(String code, String displayName) { this.code = code; this.displayName = displayName; } public String getCode() { return code; } public String getDisplayName() { return displayName; } public static Role fromCode(String code) { if (code == null || code.trim().isEmpty()) { throw new IllegalArgumentException("Role code is required"); } String normalized = code.trim().toLowerCase(Locale.ROOT); for (Role role : values()) { if (role.code.equals(normalized)) { return role; } } throw new IllegalArgumentException("Unsupported role code: " + code); } }