package com.eactive.eai.custom.alarm.policy;

import com.eactive.eai.custom.alarm.event.AlarmEvent;

public class CounterPolicy extends AlarmPolicy {

    private CounterPolicy(Builder builder) {
        super(builder);
    }

    @Override
    public boolean isAlarmTriggered(AlarmEvent event) {

        if (!event.getKey().equals(getAlarmKey())) {
            return false;
        }

        long count = event.getCondition().getCount();
        return hasExceededLimit(count);
    }

    public static Builder builder() {
        return new Builder();
    }

    public static class Builder extends AlarmPolicy.Builder<Builder> {

        @Override
        protected Builder self() {
            return this;
        }

        @Override
        public CounterPolicy build() {
            return new CounterPolicy(this);
        }
    }

}
