package cn.reghao.bnt.web.ws;

import cn.reghao.bnt.common.msg.event.EvtAgentHeartbeat;
import cn.reghao.bnt.common.msg.event.EvtAgentStart;
import cn.reghao.bnt.common.msg.event.EvtAppStatResult;
import cn.reghao.bnt.web.devops.app.service.AppDeployService;
import cn.reghao.bnt.web.devops.machine.service.MachineService;
import cn.reghao.bnt.web.ws.event.EvtAgentHeartbeatHandler;
import cn.reghao.bnt.web.ws.event.EvtAgentStartHandler;
import cn.reghao.bnt.web.ws.event.EvtAppStatResultHandler;
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;
    }
}
