package nodes

import (
	"sparrow/pkg/protocol"
	"sparrow/pkg/ruleEngine"
)

// MsgTypeSwitchNode 消息类型路由节点
// 根据消息的不同类型，路由到不同的关系节点上
type MsgTypeSwitchNode struct {
}

func (m *MsgTypeSwitchNode) Init(ctx ruleEngine.Context, config string) error {
	return nil
}

func (m *MsgTypeSwitchNode) OnMessage(ctx ruleEngine.Context, message *protocol.Message) error {
	var relationType protocol.RelationType
	switch message.Type {
	case protocol.POST_ATTRIBUTES_REQUEST:
		relationType = protocol.PostAttributes
	case protocol.POST_EVENT_REQUEST:
		relationType = protocol.PostEvent
	case protocol.CONNECT_EVENT:
		relationType = protocol.ConnectEvent
	case protocol.DISCONNECT_EVENT:
		relationType = protocol.DisconnectEvent
	default:
		relationType = protocol.Other
	}
	ctx.TellNext(message, relationType)
	return nil
}
