package probe

import (
	"fmt"
	"net/http"

	"git.loafle.net/commons_go/logging"
	cwfc "git.loafle.net/commons_go/websocket_fasthttp/client"
	oocmp "git.loafle.net/overflow/overflow_commons_go/modules/probe"
	"git.loafle.net/overflow/overflow_probes/config"
)

type SocketHandlers struct {
	cwfc.SocketHandlers
}

func (sh *SocketHandlers) OnConnect(socketContext cwfc.SocketContext, res *http.Response) {
	logging.Logger().Info(fmt.Sprintf("Probe: client has been connected res[%v]", res))

	encryptionKey := res.Header.Get(oocmp.HTTPResponseHeaderKey_Probe_SetEncryptionKey)
	config.EncryptionKey = &encryptionKey
}

func (sh *SocketHandlers) OnDisconnect(soc cwfc.Socket) {
	logging.Logger().Info(fmt.Sprintf("Probe: client has been disconnected soc[%v]", soc))

}

func newSocketHandler() cwfc.SocketHandler {
	return &SocketHandlers{}
}
