class NotificationServiceImpl implements NotificationService,Constants {

	@Override
	public Map<String, Object> unsubscribeDigestMail(final String mailId) {
		String sql = "SELECT subscriptionValue AS subscriptionValue FROM PacmanSubscriptions WHERE emailId = ?";
		String updateOrInsertQuery ;
		Object[] parameters;
		Date date = new Date();
		Boolean isUnsubscriptedAlready =  jdbcTemplate.query(sql, new Object[]{mailId}, new ResultSetExtractor<Boolean>() {
		    @Override
		    public Boolean extractData(ResultSet rs) {
		        try {
					return rs.next() ? rs.getBoolean("subscriptionValue") : null;
				} catch (SQLException e) {
					Log.error(e.getMessage());
					return null;
				}
		    }
		});
		
		if(isUnsubscriptedAlready != null) {
			updateOrInsertQuery="UPDATE PacmanSubscriptions SET emailId=?, subscriptionValue=?, modifiedDate=? WHERE emailId=?";
			parameters = new Object[] {mailId, false, date, mailId};
		} else {
			updateOrInsertQuery="INSERT INTO PacmanSubscriptions (emailId, subscriptionValue, createdDate, modifiedDate) VALUES (?,?,?,?)";
			
			parameters = new Object[] {mailId, false, date, date};
		}
		int status = jdbcTemplate.update(updateOrInsertQuery, parameters);
		Map<String, Object> response = Maps.newHashMap();
		if(status==1) {
			response.put(STATUS, true);
			response.put(MESSAGE_KEY, "You have successfully unsubscribed");
		} else {
			response.put(STATUS, false);
			response.put(MESSAGE_KEY, "Unsubscribing Failed!!!");
		}
		return response;
	}

}