package cn.reghao.devops.web.ws;

import cn.reghao.devops.web.mgr.app.service.AppDeployService;
import cn.reghao.devops.web.ws.event.EvtAgentHeartbeatHandler;
import cn.reghao.devops.web.ws.event.EvtAgentStartHandler;
import cn.reghao.devops.web.ws.event.EvtAppStatResultHandler;
import cn.reghao.devops.web.ws.event.MachineEventService;
import cn.reghao.devops.common.msg.event.EvtAgentHeartbeat;
import cn.reghao.devops.common.msg.event.EvtAgentStart;
import cn.reghao.devops.common.msg.event.EvtAppStatResult;
import cn.reghao.jutil.jdk.event.router.EventDispatcher;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author reghao
 * @date 2023-02-26 21:56:45
 */
@Configuration
public class EventDispatcherConfig {
    @Bean
    public EventDispatcher eventDispatcher(MachineEventService machineEventService, AppDeployService appDeployService) {
        EventDispatcher dispatcher = new EventDispatcher();
        dispatcher.register(EvtAgentStart.class, new EvtAgentStartHandler(machineEventService));
        dispatcher.register(EvtAgentHeartbeat.class, new EvtAgentHeartbeatHandler(machineEventService));

        dispatcher.register(EvtAppStatResult.class, new EvtAppStatResultHandler(appDeployService));
        return dispatcher;
    }
}
