class CheckInactiveIamUsersRule extends BaseRule {

	public RuleResult execute(final Map<String, String> ruleParam,Map<String, String> resourceAttributes) {
		logger.debug("========CheckInactiveIamUsersRule started=========");
		Annotation annotation = null;
		String passwordlastused = null;
		long inActiveDuration;
		long pwdInactiveDuration;
		String pwdInactiveDurationInString = ruleParam.get(PacmanRuleConstants.PD_INACTIVE_DURATION);
		
		String severity = ruleParam.get(PacmanRuleConstants.SEVERITY);
		String category = ruleParam.get(PacmanRuleConstants.CATEGORY);
		
		MDC.put("executionId", ruleParam.get("executionId")); // this is the logback Mapped Diagnostic Contex
		MDC.put("ruleId", ruleParam.get(PacmanSdkConstants.RULE_ID)); // this is the logback Mapped Diagnostic Contex
		
		List<LinkedHashMap<String,Object>> issueList = new ArrayList<>();
		LinkedHashMap<String,Object> issue = new LinkedHashMap<>();

		if (!PacmanUtils.doesAllHaveValue(pwdInactiveDurationInString,severity,category)) {
			logger.info(PacmanRuleConstants.MISSING_CONFIGURATION);
			throw new InvalidInputException(PacmanRuleConstants.MISSING_CONFIGURATION);
		}

		if (resourceAttributes != null) {
			passwordlastused = resourceAttributes.get(PacmanRuleConstants.PD_LAST_USED);
			if(!StringUtils.isEmpty(passwordlastused)){
			inActiveDuration = calculateInactiveDuration(passwordlastused);
			pwdInactiveDuration = Long.parseLong(pwdInactiveDurationInString);
			if (inActiveDuration > 0) {
				if (inActiveDuration >= pwdInactiveDuration) {
					annotation = Annotation.buildAnnotation(ruleParam,Annotation.Type.ISSUE);
					annotation.put(PacmanSdkConstants.DESCRIPTION,"Iam user is inactive since "+ inActiveDuration+ " days!!");
					annotation.put(PacmanRuleConstants.SEVERITY, severity);
					annotation.put(PacmanRuleConstants.CATEGORY, category);
					
					issue.put(PacmanRuleConstants.VIOLATION_REASON, "Iam user is inactive since "+ inActiveDuration+ " days!!");
					issue.put(passwordlastused, passwordlastused);
					issueList.add(issue);
					annotation.put("issueDetails",issueList.toString());
					logger.debug("========CheckInactiveIamUsersRule ended with annotation {} :=========",annotation);
					return new RuleResult(PacmanSdkConstants.STATUS_FAILURE,PacmanRuleConstants.FAILURE_MESSAGE, annotation);
				}
			} else {
				logger.info("Iam user is active");
			}
			}
		}
		logger.debug("========CheckInactiveIamUsersRule ended=========");
		return new RuleResult(PacmanSdkConstants.STATUS_SUCCESS,PacmanRuleConstants.SUCCESS_MESSAGE);
	}

}