class SubscriptionService {

    public SubscriptionService.DeletedSubscriptionStatus deleteSubscription(String alarmId, String subscriptionId) {
        LOGGER.info("Delete subscription {} for alarm {}", subscriptionId, alarmId);

        if (this.seyrenRepository.deleteSubscription(alarmId, subscriptionId)) {
            Alarm alarm = seyrenRepository.getAlarm(alarmId);
            if (alarm.getSubscriptions().isEmpty()) {
                if (seyrenRepository.deleteAlarm(alarmId)) {
                    return SubscriptionService.DeletedSubscriptionStatus.ALARM_DELETED;
                }
                throw new CerebroException(ErrorCode.SEYREN_ERROR, "Delete alarm '" + alarmId + "'has fail");
            }
            return SubscriptionService.DeletedSubscriptionStatus.OK;
        }

        throw new CerebroException(ErrorCode.SUBSCRIPTION_DELETE_ERROR,
            "Delete subscription '" + subscriptionId + "' on alarm '" + alarmId + "' has fail");
    }

}