// Code generated by internal/gen/api/main.go. DO NOT EDIT.

package api

import (
	"context"

	. "github.com/centrifugal/centrifugo/v6/internal/apiproto"

	"go.opentelemetry.io/otel/codes"
	"go.opentelemetry.io/otel/trace"
	"google.golang.org/grpc/status"
)

// Batch ...
func (s *grpcAPIService) Batch(ctx context.Context, req *BatchRequest) (*BatchResponse, error) {
	resp := s.api.Batch(ctx, req)
	return resp, nil
}

// Publish ...
func (s *grpcAPIService) Publish(ctx context.Context, req *PublishRequest) (*PublishResponse, error) {
	resp := s.api.Publish(ctx, req)
	if s.config.UseOpenTelemetry && resp.Error != nil {
		span := trace.SpanFromContext(ctx)
		span.SetStatus(codes.Error, resp.Error.Error())
	}
	if resp.Error != nil && s.useTransportErrorMode(ctx) {
		incError(s.api.config.Protocol, "publish", resp.Error.Code)
		statusCode := MapErrorToGRPCCode(resp.Error)
		transportError, _ := status.New(statusCode, resp.Error.Message).WithDetails(resp.Error)
		return nil, transportError.Err()
	}
	if resp.Error != nil {
		incError(s.api.config.Protocol, "publish", resp.Error.Code)
	}
	return resp, nil
}

// Broadcast ...
func (s *grpcAPIService) Broadcast(ctx context.Context, req *BroadcastRequest) (*BroadcastResponse, error) {
	resp := s.api.Broadcast(ctx, req)
	if s.config.UseOpenTelemetry && resp.Error != nil {
		span := trace.SpanFromContext(ctx)
		span.SetStatus(codes.Error, resp.Error.Error())
	}
	if resp.Error != nil && s.useTransportErrorMode(ctx) {
		incError(s.api.config.Protocol, "broadcast", resp.Error.Code)
		statusCode := MapErrorToGRPCCode(resp.Error)
		transportError, _ := status.New(statusCode, resp.Error.Message).WithDetails(resp.Error)
		return nil, transportError.Err()
	}
	if resp.Error != nil {
		incError(s.api.config.Protocol, "broadcast", resp.Error.Code)
	}
	return resp, nil
}

// Subscribe ...
func (s *grpcAPIService) Subscribe(ctx context.Context, req *SubscribeRequest) (*SubscribeResponse, error) {
	resp := s.api.Subscribe(ctx, req)
	if s.config.UseOpenTelemetry && resp.Error != nil {
		span := trace.SpanFromContext(ctx)
		span.SetStatus(codes.Error, resp.Error.Error())
	}
	if resp.Error != nil && s.useTransportErrorMode(ctx) {
		incError(s.api.config.Protocol, "subscribe", resp.Error.Code)
		statusCode := MapErrorToGRPCCode(resp.Error)
		transportError, _ := status.New(statusCode, resp.Error.Message).WithDetails(resp.Error)
		return nil, transportError.Err()
	}
	if resp.Error != nil {
		incError(s.api.config.Protocol, "subscribe", resp.Error.Code)
	}
	return resp, nil
}

// Unsubscribe ...
func (s *grpcAPIService) Unsubscribe(ctx context.Context, req *UnsubscribeRequest) (*UnsubscribeResponse, error) {
	resp := s.api.Unsubscribe(ctx, req)
	if s.config.UseOpenTelemetry && resp.Error != nil {
		span := trace.SpanFromContext(ctx)
		span.SetStatus(codes.Error, resp.Error.Error())
	}
	if resp.Error != nil && s.useTransportErrorMode(ctx) {
		incError(s.api.config.Protocol, "unsubscribe", resp.Error.Code)
		statusCode := MapErrorToGRPCCode(resp.Error)
		transportError, _ := status.New(statusCode, resp.Error.Message).WithDetails(resp.Error)
		return nil, transportError.Err()
	}
	if resp.Error != nil {
		incError(s.api.config.Protocol, "unsubscribe", resp.Error.Code)
	}
	return resp, nil
}

// Disconnect ...
func (s *grpcAPIService) Disconnect(ctx context.Context, req *DisconnectRequest) (*DisconnectResponse, error) {
	resp := s.api.Disconnect(ctx, req)
	if s.config.UseOpenTelemetry && resp.Error != nil {
		span := trace.SpanFromContext(ctx)
		span.SetStatus(codes.Error, resp.Error.Error())
	}
	if resp.Error != nil && s.useTransportErrorMode(ctx) {
		incError(s.api.config.Protocol, "disconnect", resp.Error.Code)
		statusCode := MapErrorToGRPCCode(resp.Error)
		transportError, _ := status.New(statusCode, resp.Error.Message).WithDetails(resp.Error)
		return nil, transportError.Err()
	}
	if resp.Error != nil {
		incError(s.api.config.Protocol, "disconnect", resp.Error.Code)
	}
	return resp, nil
}

// Presence ...
func (s *grpcAPIService) Presence(ctx context.Context, req *PresenceRequest) (*PresenceResponse, error) {
	resp := s.api.Presence(ctx, req)
	if s.config.UseOpenTelemetry && resp.Error != nil {
		span := trace.SpanFromContext(ctx)
		span.SetStatus(codes.Error, resp.Error.Error())
	}
	if resp.Error != nil && s.useTransportErrorMode(ctx) {
		incError(s.api.config.Protocol, "presence", resp.Error.Code)
		statusCode := MapErrorToGRPCCode(resp.Error)
		transportError, _ := status.New(statusCode, resp.Error.Message).WithDetails(resp.Error)
		return nil, transportError.Err()
	}
	if resp.Error != nil {
		incError(s.api.config.Protocol, "presence", resp.Error.Code)
	}
	return resp, nil
}

// PresenceStats ...
func (s *grpcAPIService) PresenceStats(ctx context.Context, req *PresenceStatsRequest) (*PresenceStatsResponse, error) {
	resp := s.api.PresenceStats(ctx, req)
	if s.config.UseOpenTelemetry && resp.Error != nil {
		span := trace.SpanFromContext(ctx)
		span.SetStatus(codes.Error, resp.Error.Error())
	}
	if resp.Error != nil && s.useTransportErrorMode(ctx) {
		incError(s.api.config.Protocol, "presence_stats", resp.Error.Code)
		statusCode := MapErrorToGRPCCode(resp.Error)
		transportError, _ := status.New(statusCode, resp.Error.Message).WithDetails(resp.Error)
		return nil, transportError.Err()
	}
	if resp.Error != nil {
		incError(s.api.config.Protocol, "presence_stats", resp.Error.Code)
	}
	return resp, nil
}

// History ...
func (s *grpcAPIService) History(ctx context.Context, req *HistoryRequest) (*HistoryResponse, error) {
	resp := s.api.History(ctx, req)
	if s.config.UseOpenTelemetry && resp.Error != nil {
		span := trace.SpanFromContext(ctx)
		span.SetStatus(codes.Error, resp.Error.Error())
	}
	if resp.Error != nil && s.useTransportErrorMode(ctx) {
		incError(s.api.config.Protocol, "history", resp.Error.Code)
		statusCode := MapErrorToGRPCCode(resp.Error)
		transportError, _ := status.New(statusCode, resp.Error.Message).WithDetails(resp.Error)
		return nil, transportError.Err()
	}
	if resp.Error != nil {
		incError(s.api.config.Protocol, "history", resp.Error.Code)
	}
	return resp, nil
}

// HistoryRemove ...
func (s *grpcAPIService) HistoryRemove(ctx context.Context, req *HistoryRemoveRequest) (*HistoryRemoveResponse, error) {
	resp := s.api.HistoryRemove(ctx, req)
	if s.config.UseOpenTelemetry && resp.Error != nil {
		span := trace.SpanFromContext(ctx)
		span.SetStatus(codes.Error, resp.Error.Error())
	}
	if resp.Error != nil && s.useTransportErrorMode(ctx) {
		incError(s.api.config.Protocol, "history_remove", resp.Error.Code)
		statusCode := MapErrorToGRPCCode(resp.Error)
		transportError, _ := status.New(statusCode, resp.Error.Message).WithDetails(resp.Error)
		return nil, transportError.Err()
	}
	if resp.Error != nil {
		incError(s.api.config.Protocol, "history_remove", resp.Error.Code)
	}
	return resp, nil
}

// Info ...
func (s *grpcAPIService) Info(ctx context.Context, req *InfoRequest) (*InfoResponse, error) {
	resp := s.api.Info(ctx, req)
	if s.config.UseOpenTelemetry && resp.Error != nil {
		span := trace.SpanFromContext(ctx)
		span.SetStatus(codes.Error, resp.Error.Error())
	}
	if resp.Error != nil && s.useTransportErrorMode(ctx) {
		incError(s.api.config.Protocol, "info", resp.Error.Code)
		statusCode := MapErrorToGRPCCode(resp.Error)
		transportError, _ := status.New(statusCode, resp.Error.Message).WithDetails(resp.Error)
		return nil, transportError.Err()
	}
	if resp.Error != nil {
		incError(s.api.config.Protocol, "info", resp.Error.Code)
	}
	return resp, nil
}

// RPC ...
func (s *grpcAPIService) RPC(ctx context.Context, req *RPCRequest) (*RPCResponse, error) {
	resp := s.api.RPC(ctx, req)
	if s.config.UseOpenTelemetry && resp.Error != nil {
		span := trace.SpanFromContext(ctx)
		span.SetStatus(codes.Error, resp.Error.Error())
	}
	if resp.Error != nil && s.useTransportErrorMode(ctx) {
		incError(s.api.config.Protocol, "rpc", resp.Error.Code)
		statusCode := MapErrorToGRPCCode(resp.Error)
		transportError, _ := status.New(statusCode, resp.Error.Message).WithDetails(resp.Error)
		return nil, transportError.Err()
	}
	if resp.Error != nil {
		incError(s.api.config.Protocol, "rpc", resp.Error.Code)
	}
	return resp, nil
}

// Refresh ...
func (s *grpcAPIService) Refresh(ctx context.Context, req *RefreshRequest) (*RefreshResponse, error) {
	resp := s.api.Refresh(ctx, req)
	if s.config.UseOpenTelemetry && resp.Error != nil {
		span := trace.SpanFromContext(ctx)
		span.SetStatus(codes.Error, resp.Error.Error())
	}
	if resp.Error != nil && s.useTransportErrorMode(ctx) {
		incError(s.api.config.Protocol, "refresh", resp.Error.Code)
		statusCode := MapErrorToGRPCCode(resp.Error)
		transportError, _ := status.New(statusCode, resp.Error.Message).WithDetails(resp.Error)
		return nil, transportError.Err()
	}
	if resp.Error != nil {
		incError(s.api.config.Protocol, "refresh", resp.Error.Code)
	}
	return resp, nil
}

// Channels ...
func (s *grpcAPIService) Channels(ctx context.Context, req *ChannelsRequest) (*ChannelsResponse, error) {
	resp := s.api.Channels(ctx, req)
	if s.config.UseOpenTelemetry && resp.Error != nil {
		span := trace.SpanFromContext(ctx)
		span.SetStatus(codes.Error, resp.Error.Error())
	}
	if resp.Error != nil && s.useTransportErrorMode(ctx) {
		incError(s.api.config.Protocol, "channels", resp.Error.Code)
		statusCode := MapErrorToGRPCCode(resp.Error)
		transportError, _ := status.New(statusCode, resp.Error.Message).WithDetails(resp.Error)
		return nil, transportError.Err()
	}
	if resp.Error != nil {
		incError(s.api.config.Protocol, "channels", resp.Error.Code)
	}
	return resp, nil
}
