class ComplianceController implements Constants {

    @ApiOperation(httpMethod = "POST", value = "Adding issue exception to the corresponding target type")
    @RequestMapping(path = "/v2/issue/add-exception", method = RequestMethod.POST)
    @ApiResponses(value = { @ApiResponse(code = 200, message = "Successfully Added Issue Exception"),
            @ApiResponse(code = 401, message = "You are not authorized to Add Issue Exception"),
            @ApiResponse(code = 403, message = "Add Issue Exception is forbidden") })
    @ResponseBody
    
    public ResponseEntity<Object> addIssuesException(
            @ApiParam(value = "Provide Issue Exception Details", required = true) @RequestBody(required = true) IssuesException issuesException) {
        try {
            
            if (issuesException.getExceptionGrantedDate() == null) {
                return ResponseUtils.buildFailureResponse(new Exception("Exception Granted Date is mandatory"));
            }
            if (issuesException.getExceptionEndDate() == null) {
                return ResponseUtils.buildFailureResponse(new Exception("Exception End Date is mandatory"));
            }
            
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Calendar cal = Calendar.getInstance();
            cal.setTimeZone(TimeZone.getTimeZone("UTC"));
            if(sdf.parse(sdf.format(issuesException.getExceptionGrantedDate())).before(sdf.parse(sdf.format(cal.getTime())))) {
                return ResponseUtils.buildFailureResponse(new Exception("Exception Granted Date cannot be earlier date than today"));
            }
            if(sdf.parse(sdf.format(issuesException.getExceptionEndDate())).before(sdf.parse(sdf.format(cal.getTime())))) {
                return ResponseUtils.buildFailureResponse(new Exception("Exception End Date cannot be earlier date than today"));
            }
            if(issuesException.getIssueIds().isEmpty()) {
                return ResponseUtils.buildFailureResponse(new Exception("Atleast one issue id is required"));
            }
            return ResponseUtils.buildSucessResponse(complianceService.addMultipleIssueException(issuesException));
        } catch (ServiceException | ParseException exception) {
            return ResponseUtils.buildFailureResponse(exception);
        }
    }

}