// Code generated by protoc-gen-triple. DO NOT EDIT.
//
// Source: chat.proto
package chat

import (
	"context"
	"net/http"
)

import (
	"dubbo.apache.org/dubbo-go/v3"
	"dubbo.apache.org/dubbo-go/v3/client"
	"dubbo.apache.org/dubbo-go/v3/common"
	"dubbo.apache.org/dubbo-go/v3/common/constant"
	"dubbo.apache.org/dubbo-go/v3/protocol/triple/triple_protocol"
	"dubbo.apache.org/dubbo-go/v3/server"
)

// This is a compile-time assertion to ensure that this generated file and the Triple package
// are compatible. If you get a compiler error that this constant is not defined, this code was
// generated with a version of Triple newer than the one compiled into your binary. You can fix the
// problem by either regenerating this code with an older version of Triple or updating the Triple
// version compiled into your binary.
const _ = triple_protocol.IsAtLeastVersion0_1_0

const (
	// ChatServiceName is the fully-qualified name of the ChatService service.
	ChatServiceName = "chat.ChatService"
)

// These constants are the fully-qualified names of the RPCs defined in this package. They're
// exposed at runtime as procedure and as the final two segments of the HTTP route.
//
// Note that these are different from the fully-qualified method names used by
// google.golang.org/protobuf/reflect/protoreflect. To convert from these constants to
// reflection-formatted method names, remove the leading slash and convert the remaining slash to a
// period.
const (
	// ChatServiceChatProcedure is the fully-qualified name of the ChatService's Chat RPC.
	ChatServiceChatProcedure = "/chat.ChatService/Chat"
)

var (
	_ ChatService = (*ChatServiceImpl)(nil)

	_ ChatService_ChatClient = (*ChatServiceChatClient)(nil)

	_ ChatService_ChatServer = (*ChatServiceChatServer)(nil)
)

// ChatService is a client for the chat.ChatService service.
type ChatService interface {
	Chat(ctx context.Context, req *ChatRequest, opts ...client.CallOption) (ChatService_ChatClient, error)
}

// NewChatService constructs a client for the chat.ChatService service.
func NewChatService(cli *client.Client, opts ...client.ReferenceOption) (ChatService, error) {
	conn, err := cli.DialWithInfo("chat.ChatService", &ChatService_ClientInfo, opts...)
	if err != nil {
		return nil, err
	}
	return &ChatServiceImpl{
		conn: conn,
	}, nil
}

func SetConsumerChatService(srv common.RPCService) {
	dubbo.SetConsumerServiceWithInfo(srv, &ChatService_ClientInfo)
}

// ChatServiceImpl implements ChatService.
type ChatServiceImpl struct {
	conn *client.Connection
}

func (c *ChatServiceImpl) Chat(ctx context.Context, req *ChatRequest, opts ...client.CallOption) (ChatService_ChatClient, error) {
	stream, err := c.conn.CallServerStream(ctx, req, "Chat", opts...)
	if err != nil {
		return nil, err
	}
	rawStream := stream.(*triple_protocol.ServerStreamForClient)
	return &ChatServiceChatClient{rawStream}, nil
}

type ChatService_ChatClient interface {
	Recv() bool
	ResponseHeader() http.Header
	ResponseTrailer() http.Header
	Msg() *ChatResponse
	Err() error
	Conn() (triple_protocol.StreamingClientConn, error)
	Close() error
}

type ChatServiceChatClient struct {
	*triple_protocol.ServerStreamForClient
}

func (cli *ChatServiceChatClient) Recv() bool {
	msg := new(ChatResponse)
	return cli.ServerStreamForClient.Receive(msg)
}

func (cli *ChatServiceChatClient) Msg() *ChatResponse {
	msg := cli.ServerStreamForClient.Msg()
	if msg == nil {
		return new(ChatResponse)
	}
	return msg.(*ChatResponse)
}

func (cli *ChatServiceChatClient) Conn() (triple_protocol.StreamingClientConn, error) {
	return cli.ServerStreamForClient.Conn()
}

var ChatService_ClientInfo = client.ClientInfo{
	InterfaceName: "chat.ChatService",
	MethodNames:   []string{"Chat"},
	ConnectionInjectFunc: func(dubboCliRaw interface{}, conn *client.Connection) {
		dubboCli := dubboCliRaw.(*ChatServiceImpl)
		dubboCli.conn = conn
	},
}

// ChatServiceHandler is an implementation of the chat.ChatService service.
type ChatServiceHandler interface {
	Chat(context.Context, *ChatRequest, ChatService_ChatServer) error
}

func RegisterChatServiceHandler(srv *server.Server, hdlr ChatServiceHandler, opts ...server.ServiceOption) error {
	return srv.Register(hdlr, &ChatService_ServiceInfo, opts...)
}

func SetProviderChatService(srv common.RPCService) {
	dubbo.SetProviderServiceWithInfo(srv, &ChatService_ServiceInfo)
}

type ChatService_ChatServer interface {
	Send(*ChatResponse) error
	ResponseHeader() http.Header
	ResponseTrailer() http.Header
	Conn() triple_protocol.StreamingHandlerConn
}

type ChatServiceChatServer struct {
	*triple_protocol.ServerStream
}

func (g *ChatServiceChatServer) Send(msg *ChatResponse) error {
	return g.ServerStream.Send(msg)
}

var ChatService_ServiceInfo = server.ServiceInfo{
	InterfaceName: "chat.ChatService",
	ServiceType:   (*ChatServiceHandler)(nil),
	Methods: []server.MethodInfo{
		{
			Name: "Chat",
			Type: constant.CallServerStream,
			ReqInitFunc: func() interface{} {
				return new(ChatRequest)
			},
			StreamInitFunc: func(baseStream interface{}) interface{} {
				return &ChatServiceChatServer{baseStream.(*triple_protocol.ServerStream)}
			},
			MethodFunc: func(ctx context.Context, args []interface{}, handler interface{}) (interface{}, error) {
				req := args[0].(*ChatRequest)
				stream := args[1].(ChatService_ChatServer)
				if err := handler.(ChatServiceHandler).Chat(ctx, req, stream); err != nil {
					return nil, err
				}
				return nil, nil
			},
		},
	},
}
