package cn.reghao.devops.mgr.ws;

import cn.reghao.devops.mgr.app.service.AppDeployService;
import cn.reghao.devops.mgr.machine.service.MachineService;
import cn.reghao.devops.mgr.ws.event.EvtAgentHeartbeatHandler;
import cn.reghao.devops.mgr.ws.event.EvtAgentStartHandler;
import cn.reghao.devops.mgr.ws.event.EvtAppStatResultHandler;
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(MachineService machineService, AppDeployService appDeployService) {
        EventDispatcher dispatcher = new EventDispatcher();
        dispatcher.register(EvtAgentStart.class, new EvtAgentStartHandler(machineService));
        dispatcher.register(EvtAgentHeartbeat.class, new EvtAgentHeartbeatHandler(machineService));

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