package jnpf.cultivate.event.impl.trigger.distribute;

import jnpf.cultivate.event.JnpfApplicationEventService;
import jnpf.cultivate.event.base.TriggerProcessor;
import jnpf.model.cultivate.bo.TriggerEventBO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Component
@Slf4j
@SuppressWarnings("unchecked")
public class JnpfApplicationEventExamIdentificationTrigger implements JnpfApplicationEventService {

    @Resource
    private List<TriggerProcessor> triggerProcessors;


    @Override
    public boolean isSupportedCourseEvent(Object event) {
        return event instanceof TriggerEventBO;
    }

    @Override
    public void handlerCourseEvent(Object courseEvent) {
        TriggerEventBO triggerEventDTO = (TriggerEventBO) courseEvent;
        // 事件处理
        triggerProcessors.forEach(triggerProcessor -> {
            if (triggerProcessor.triggerTypeConfirmation(triggerEventDTO.getTriggerEventType())) {
                triggerProcessor.triggerHandle(triggerEventDTO);
            }
        });
    }


}
