package service

import (
	"common/discover"
	"common/discover/common"
	"common/net/grpc/resolver"
	"common/proto/ss/grpc_pb"
)

func SceneNewClient(sid ...int64) (grpc_pb.SceneClient, error) {
	c, err := discover.FindServer(common.KeyDiscoverScene, sid...)
	if err != nil {
		return nil, err
	}
	return grpc_pb.NewSceneClient(c), nil
}

func SceneNewClientLB() (grpc_pb.SceneClient, error) {
	c, err := resolver.GetGrpcClientConn("etcd:///" + common.KeyDiscoverServiceNameScene)
	if err != nil {
		return nil, err
	}
	return grpc_pb.NewSceneClient(c), nil
}

func SceneNewBroadcastClient() map[int64]grpc_pb.SceneClient {
	clientM := make(map[int64]grpc_pb.SceneClient)
	connM := discover.FindServerAll(common.KeyDiscoverScene)
	for sid, conn := range connM {
		clientM[sid] = grpc_pb.NewSceneClient(conn)
	}
	return clientM
}
