package com.iqser.red.service.persistence.management.v1.processor.roles;

import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.ADD_COMMENT;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.ADD_DICTIONARY_ENTRY;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.ADD_DOSSIER_DICTIONARY_ENTRY;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.ADD_UPDATE_DICTIONARY_TYPE;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.ADD_UPDATE_DOSSIER;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.ADD_UPDATE_DOSSIER_DICTIONARY_TYPE;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.ARCHIVE_DOSSIER;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.CONVERT_HIGHLIGHTS;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.CREATE_TENANT;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.DELETE_COMMENT;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.DELETE_DICTIONARY_ENTRY;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.DELETE_DICTIONARY_TYPE;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.DELETE_DOSSIER;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.DELETE_DOSSIER_DICTIONARY_ENTRY;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.DELETE_DOSSIER_DICTIONARY_TYPE;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.DELETE_FILE;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.DELETE_HIGHLIGHTS;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.DELETE_IMPORTED_REDACTIONS;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.DELETE_MANUAL_REDACTION;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.DELETE_REPORT_TEMPLATE;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.DEPLOYMENT_INFO;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.DOWNLOAD_ANNOTATED_FILE;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.DOWNLOAD_ORIGINAL_FILE;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.DOWNLOAD_REDACTED_FILE;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.DOWNLOAD_REDACTION_PREVIEW_FILE;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.DOWNLOAD_REPORT_TEMPLATE;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.DO_MANUAL_REDACTION;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.EXCLUDE_INCLUDE_FILE;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.EXCLUDE_INCLUDE_PAGES;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.GET_HIGHLIGHTS;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.GET_REPORT_TEMPLATES;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.GET_RSS;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.GET_TENANTS;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.MANAGE_ACL_PERMISSIONS;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.MANAGE_USER_PREFERENCES;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.MANAGE_VIEWED_PAGES;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.PROCESS_DOWNLOAD;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.PROCESS_MANUAL_REDACTION_REQUEST;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.PROCESS_TEXT_HIGHLIGHTS;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.READ_ALL_USERS;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.READ_APP_CONFIG;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.READ_COLORS;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.READ_DICTIONARY_TYPES;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.READ_DIGITAL_SIGNATURE;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.READ_DOSSIER;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.READ_DOSSIER_ATTRIBUTES;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.READ_DOSSIER_ATTRIBUTES_CONFIG;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.READ_DOSSIER_STATUS;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.READ_DOSSIER_TEMPLATES;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.READ_DOWNLOAD_STATUS;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.READ_FILE_ATTRIBUTES_CONFIG;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.READ_FILE_STATUS;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.READ_GENERAL_CONFIGURATION;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.READ_LEGAL_BASIS;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.READ_LICENSE;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.READ_LICENSE_REPORT;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.READ_MANUAL_REDACTIONS;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.READ_NOTIFICATIONS;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.READ_REDACTION_LOG;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.READ_RULES;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.READ_SMTP_CONFIGURATION;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.READ_USERS;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.READ_VERSIONS;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.READ_WATERMARK;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.REANALYZE_DOSSIER;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.REANALYZE_FILE;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.REINDEX;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.REQUEST_MANUAL_REDACTION;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.ROTATE_PAGE;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.SEARCH;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.SEARCH_AUDIT_LOG;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.SET_REVIEWER;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.SET_STATUS_APPROVED;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.SET_STATUS_UNDER_APPROVAL;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.UNARCHIVE_DOSSIER;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.UPDATE_LICENSE;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.UPDATE_MY_PROFILE;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.UPDATE_NOTIFICATIONS;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.UPLOAD_FILE;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.UPLOAD_REPORT_TEMPLATE;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.WRITE_APP_CONFIG;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.WRITE_COLORS;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.WRITE_DIGITAL_SIGNATURE;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.WRITE_DOSSIER_ATTRIBUTES;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.WRITE_DOSSIER_ATTRIBUTES_CONFIG;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.WRITE_DOSSIER_STATUS;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.WRITE_DOSSIER_TEMPLATES;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.WRITE_FILE_ATTRIBUTES;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.WRITE_FILE_ATTRIBUTES_CONFIG;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.WRITE_GENERAL_CONFIGURATION;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.WRITE_LEGAL_BASIS;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.WRITE_RULES;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.WRITE_SMTP_CONFIGURATION;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.WRITE_USERS;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.WRITE_WATERMARK;

import java.util.Collection;
import java.util.Map;
import java.util.Set;

import com.google.common.collect.Sets;

public final class ApplicationRoles {

    public static final String RED_USER_ROLE = "RED_USER";
    public static final String RED_MANAGER_ROLE = "RED_MANAGER";
    public static final String RED_ADMIN_ROLE = "RED_ADMIN";
    public static final String RED_USER_ADMIN_ROLE = "RED_USER_ADMIN";

    public static final Set<String> UNMAPPED_ACTION_ROLES = Sets.newHashSet(UNARCHIVE_DOSSIER, UPDATE_LICENSE, GET_RSS);

    public static final Set<String> RED_USER_ACTION_ROLES = Sets.newHashSet(ADD_COMMENT,
            READ_LICENSE,
            READ_APP_CONFIG,
            READ_DOSSIER_STATUS,
            ADD_DOSSIER_DICTIONARY_ENTRY,
            DO_MANUAL_REDACTION,
            ADD_UPDATE_DOSSIER_DICTIONARY_TYPE,
            DELETE_COMMENT,
            DELETE_DOSSIER_DICTIONARY_ENTRY,
            DELETE_DOSSIER_DICTIONARY_TYPE,
            DELETE_FILE,
            DELETE_MANUAL_REDACTION,
            DOWNLOAD_ANNOTATED_FILE,
            DOWNLOAD_ORIGINAL_FILE,
            DOWNLOAD_REDACTED_FILE,
            DOWNLOAD_REDACTION_PREVIEW_FILE,
            DOWNLOAD_REPORT_TEMPLATE,
            EXCLUDE_INCLUDE_FILE,
            EXCLUDE_INCLUDE_PAGES,
            GET_REPORT_TEMPLATES,
            MANAGE_USER_PREFERENCES,
            MANAGE_VIEWED_PAGES,
            PROCESS_DOWNLOAD,
            PROCESS_MANUAL_REDACTION_REQUEST,
            READ_COLORS,
            READ_DICTIONARY_TYPES,
            READ_DIGITAL_SIGNATURE,
            READ_DOSSIER,
            READ_DOSSIER_ATTRIBUTES,
            READ_DOSSIER_ATTRIBUTES_CONFIG,
            READ_DOSSIER_TEMPLATES,
            READ_DOWNLOAD_STATUS,
            READ_FILE_ATTRIBUTES_CONFIG,
            READ_FILE_STATUS,
            READ_GENERAL_CONFIGURATION,
            READ_LEGAL_BASIS,
            READ_MANUAL_REDACTIONS,
            READ_NOTIFICATIONS,
            READ_REDACTION_LOG,
            READ_RULES,
            READ_USERS,
            READ_VERSIONS,
            READ_WATERMARK,
            REANALYZE_DOSSIER,
            REANALYZE_FILE,
            REQUEST_MANUAL_REDACTION,
            ROTATE_PAGE,
            SEARCH,
            SEARCH_AUDIT_LOG,
            SET_REVIEWER,
            SET_STATUS_APPROVED,
            SET_STATUS_UNDER_APPROVAL,
            UPDATE_MY_PROFILE,
            UPDATE_NOTIFICATIONS,
            UPLOAD_FILE,
            WRITE_FILE_ATTRIBUTES,
            PROCESS_TEXT_HIGHLIGHTS,
            GET_HIGHLIGHTS,
            CONVERT_HIGHLIGHTS,
            DELETE_HIGHLIGHTS,
            DELETE_IMPORTED_REDACTIONS);

    public static final Set<String> RED_ADMIN_ACTION_ROLES = Sets.newHashSet(ADD_DICTIONARY_ENTRY,
            ADD_UPDATE_DICTIONARY_TYPE,
            WRITE_DOSSIER_STATUS,
            READ_DOSSIER_STATUS,
            DELETE_DICTIONARY_ENTRY,
            DELETE_DICTIONARY_TYPE,
            DELETE_REPORT_TEMPLATE,
            DOWNLOAD_REPORT_TEMPLATE,
            GET_REPORT_TEMPLATES,
            MANAGE_USER_PREFERENCES,
            READ_COLORS,
            READ_DICTIONARY_TYPES,
            READ_DIGITAL_SIGNATURE,
            READ_DOSSIER_ATTRIBUTES,
            READ_DOSSIER_ATTRIBUTES_CONFIG,
            READ_DOSSIER_TEMPLATES,
            READ_FILE_ATTRIBUTES_CONFIG,
            READ_LEGAL_BASIS,
            READ_LICENSE_REPORT,
            READ_NOTIFICATIONS,
            READ_RULES,
            READ_SMTP_CONFIGURATION,
            READ_VERSIONS,
            READ_WATERMARK,
            REINDEX,
            SEARCH_AUDIT_LOG,
            UPDATE_NOTIFICATIONS,
            UPLOAD_REPORT_TEMPLATE,
            WRITE_COLORS,
            WRITE_DIGITAL_SIGNATURE,
            WRITE_DOSSIER_ATTRIBUTES_CONFIG,
            WRITE_DOSSIER_TEMPLATES,
            WRITE_FILE_ATTRIBUTES_CONFIG,
            WRITE_GENERAL_CONFIGURATION,
            WRITE_LEGAL_BASIS,
            WRITE_RULES,
            WRITE_SMTP_CONFIGURATION,
            WRITE_WATERMARK,
            WRITE_APP_CONFIG,
            MANAGE_ACL_PERMISSIONS,
            CREATE_TENANT,
            GET_TENANTS,
            DEPLOYMENT_INFO);

    public static final Set<String> RED_MANAGER_ACTION_ROLES = Sets.newHashSet(ADD_UPDATE_DOSSIER, ARCHIVE_DOSSIER, DELETE_DOSSIER, WRITE_DOSSIER_ATTRIBUTES);

    public static final Set<String> RED_USER_ADMIN_ACTION_ROLES = Sets.newHashSet(MANAGE_USER_PREFERENCES,
            READ_ALL_USERS,
            READ_DOSSIER,
            READ_APP_CONFIG,
            READ_GENERAL_CONFIGURATION,
            READ_GENERAL_CONFIGURATION,
            READ_NOTIFICATIONS,
            READ_USERS,
            UPDATE_MY_PROFILE,
            UPDATE_NOTIFICATIONS,
            WRITE_USERS,
            READ_LICENSE);

    public static final Map<String, Set<String>> ROLE_DATA = Map.of(RED_USER_ROLE,
            RED_USER_ACTION_ROLES,
            RED_MANAGER_ROLE,
            RED_MANAGER_ACTION_ROLES,
            RED_ADMIN_ROLE,
            RED_ADMIN_ACTION_ROLES,
            RED_USER_ADMIN_ROLE,
            RED_USER_ADMIN_ACTION_ROLES);


    private ApplicationRoles() {}


    public static void validateRoles(Collection<String> roles) {

        for (String role : roles) {
            if (!ROLE_DATA.containsKey(role)) {
                throw new IllegalArgumentException("Invalid Role: " + role);
            }
        }
    }

}
