package mx.gob.slp.baseadminweb.configuration.security;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

final class CognitoRoleMapper {

    private CognitoRoleMapper() {
    }

    static List<String> toRoles(Collection<String> groups, CognitoProperties properties) {
        if (groups == null || groups.isEmpty()) {
            return List.of();
        }

        List<String> roles = new ArrayList<>();
        for (String group : groups) {
            if (properties.getScannerGroup().equalsIgnoreCase(group)) {
                roles.add("ROLE_SCANNER");
            } else if (properties.getAdminGroup().equalsIgnoreCase(group)) {
                roles.add("ROLE_ADMIN");
            } else {
                roles.add("ROLE_" + group.toUpperCase());
            }
        }
        return roles;
    }
}