class MassUpdateRulesCheck extends ActionHandler {

    @Override
    public ItemStatus execute(WorkerParameters param, HandlerIO handler) {
        try {
            RuleActions ruleActions = JsonHandler.getFromJsonNode(handler.getJsonFromWorkspace("actions.json"), RuleActions.class);
            if (ruleActions.isRuleActionsEmpty()) {
                MassUpdateErrorInfo errorInfo = new MassUpdateErrorInfo("RULE_ACTION_EMPTY", "Rule actions used to update units is empty.");
                return buildItemStatus(PLUGIN_NAME, KO, errorInfo);
            }

            List<String> duplicateKeys = getDuplicateKeys(ruleActions);
            if (!duplicateKeys.isEmpty()) {
                String message = String.format("Invalid rule actions query: duplicate rules '%s'.", String.join(", ", duplicateKeys));
                return buildItemStatusWithMessage(PLUGIN_NAME, KO, message);
            }

            boolean deleteOrAddSameAUP = isTryingToAddAndDeleteAUP(ruleActions.getAddOrUpdateMetadata(), ruleActions.getDeleteMetadata());
            if (deleteOrAddSameAUP) {
                String message = String.format("Invalid AUP query: duplicate in add or delete '%s'.", ruleActions.getAddOrUpdateMetadata().getArchiveUnitProfile());
                return buildItemStatusWithMessage(PLUGIN_NAME, KO, message);
            }

            List<String> unknownAddClassificationLevels = ruleActions.getAdd()
                .stream()
                .filter(rule -> Objects.nonNull(rule.get(TAG_RULE_CLASSIFICATION)))
                .map(rule -> rule.get(TAG_RULE_CLASSIFICATION).getClassificationLevel())
                .filter(Objects::nonNull)
                .filter(classificationLevel -> !classificationLevels.contains(classificationLevel))
                .collect(Collectors.toList());

            if (!unknownAddClassificationLevels.isEmpty()) {
                String message = String.format("Unknown classification level '%s' in added rule action.", String.join(", ", unknownAddClassificationLevels));
                alertService.createAlert(message);
                return buildItemStatusWithMessage(PLUGIN_NAME, KO, message);
            }

            List<String> unknownUpdateClassificationLevels = ruleActions.getUpdate()
                .stream()
                .filter(rule -> Objects.nonNull(rule.get(TAG_RULE_CLASSIFICATION)))
                .map(rule -> rule.get(TAG_RULE_CLASSIFICATION).getClassificationLevel())
                .filter(Objects::nonNull)
                .filter(classificationLevel -> !classificationLevels.contains(classificationLevel))
                .collect(Collectors.toList());

            if (!unknownUpdateClassificationLevels.isEmpty()) {
                String message = String.format("Unknown classification level '%s' in updated rule action.", String.join(", ", unknownUpdateClassificationLevels));
                alertService.createAlert(message);
                return buildItemStatusWithMessage(PLUGIN_NAME, KO, message);
            }

            return buildItemStatus(PLUGIN_NAME, OK, EventDetails.of("Step OK."));
        } catch (VitamException e) {
            LOGGER.error(e);
            return buildItemStatus(PLUGIN_NAME, KO, EventDetails.of("Unexpected error."));
        }
    }

    public  MassUpdateRulesCheck();
    @VisibleForTesting public  MassUpdateRulesCheck(AlertService alertService, List<String> classificationLevels);

}