// Code generated by protoc-gen-twirp v8.1.3, DO NOT EDIT.
// source: livekit_connector.proto

package livekit

import context "context"
import fmt "fmt"
import http "net/http"
import io "io"
import json "encoding/json"
import strconv "strconv"
import strings "strings"

import protojson "google.golang.org/protobuf/encoding/protojson"
import proto "google.golang.org/protobuf/proto"
import twirp "github.com/twitchtv/twirp"
import ctxsetters "github.com/twitchtv/twirp/ctxsetters"

// Version compatibility assertion.
// If the constant is not defined in the package, that likely means
// the package needs to be updated to work with this generated code.
// See https://twitchtv.github.io/twirp/docs/version_matrix.html
const _ = twirp.TwirpPackageMinVersion_8_1_0

// ===================
// Connector Interface
// ===================

type Connector interface {
	DialWhatsAppCall(context.Context, *DialWhatsAppCallRequest) (*DialWhatsAppCallResponse, error)

	DisconnectWhatsAppCall(context.Context, *DisconnectWhatsAppCallRequest) (*DisconnectWhatsAppCallResponse, error)

	ConnectWhatsAppCall(context.Context, *ConnectWhatsAppCallRequest) (*ConnectWhatsAppCallResponse, error)

	AcceptWhatsAppCall(context.Context, *AcceptWhatsAppCallRequest) (*AcceptWhatsAppCallResponse, error)

	ConnectTwilioCall(context.Context, *ConnectTwilioCallRequest) (*ConnectTwilioCallResponse, error)
}

// =========================
// Connector Protobuf Client
// =========================

type connectorProtobufClient struct {
	client      HTTPClient
	urls        [5]string
	interceptor twirp.Interceptor
	opts        twirp.ClientOptions
}

// NewConnectorProtobufClient creates a Protobuf client that implements the Connector interface.
// It communicates using Protobuf and can be configured with a custom HTTPClient.
func NewConnectorProtobufClient(baseURL string, client HTTPClient, opts ...twirp.ClientOption) Connector {
	if c, ok := client.(*http.Client); ok {
		client = withoutRedirects(c)
	}

	clientOpts := twirp.ClientOptions{}
	for _, o := range opts {
		o(&clientOpts)
	}

	// Using ReadOpt allows backwards and forwards compatibility with new options in the future
	literalURLs := false
	_ = clientOpts.ReadOpt("literalURLs", &literalURLs)
	var pathPrefix string
	if ok := clientOpts.ReadOpt("pathPrefix", &pathPrefix); !ok {
		pathPrefix = "/twirp" // default prefix
	}

	// Build method URLs: <baseURL>[<prefix>]/<package>.<Service>/<Method>
	serviceURL := sanitizeBaseURL(baseURL)
	serviceURL += baseServicePath(pathPrefix, "livekit", "Connector")
	urls := [5]string{
		serviceURL + "DialWhatsAppCall",
		serviceURL + "DisconnectWhatsAppCall",
		serviceURL + "ConnectWhatsAppCall",
		serviceURL + "AcceptWhatsAppCall",
		serviceURL + "ConnectTwilioCall",
	}

	return &connectorProtobufClient{
		client:      client,
		urls:        urls,
		interceptor: twirp.ChainInterceptors(clientOpts.Interceptors...),
		opts:        clientOpts,
	}
}

func (c *connectorProtobufClient) DialWhatsAppCall(ctx context.Context, in *DialWhatsAppCallRequest) (*DialWhatsAppCallResponse, error) {
	ctx = ctxsetters.WithPackageName(ctx, "livekit")
	ctx = ctxsetters.WithServiceName(ctx, "Connector")
	ctx = ctxsetters.WithMethodName(ctx, "DialWhatsAppCall")
	caller := c.callDialWhatsAppCall
	if c.interceptor != nil {
		caller = func(ctx context.Context, req *DialWhatsAppCallRequest) (*DialWhatsAppCallResponse, error) {
			resp, err := c.interceptor(
				func(ctx context.Context, req interface{}) (interface{}, error) {
					typedReq, ok := req.(*DialWhatsAppCallRequest)
					if !ok {
						return nil, twirp.InternalError("failed type assertion req.(*DialWhatsAppCallRequest) when calling interceptor")
					}
					return c.callDialWhatsAppCall(ctx, typedReq)
				},
			)(ctx, req)
			if resp != nil {
				typedResp, ok := resp.(*DialWhatsAppCallResponse)
				if !ok {
					return nil, twirp.InternalError("failed type assertion resp.(*DialWhatsAppCallResponse) when calling interceptor")
				}
				return typedResp, err
			}
			return nil, err
		}
	}
	return caller(ctx, in)
}

func (c *connectorProtobufClient) callDialWhatsAppCall(ctx context.Context, in *DialWhatsAppCallRequest) (*DialWhatsAppCallResponse, error) {
	out := new(DialWhatsAppCallResponse)
	ctx, err := doProtobufRequest(ctx, c.client, c.opts.Hooks, c.urls[0], in, out)
	if err != nil {
		twerr, ok := err.(twirp.Error)
		if !ok {
			twerr = twirp.InternalErrorWith(err)
		}
		callClientError(ctx, c.opts.Hooks, twerr)
		return nil, err
	}

	callClientResponseReceived(ctx, c.opts.Hooks)

	return out, nil
}

func (c *connectorProtobufClient) DisconnectWhatsAppCall(ctx context.Context, in *DisconnectWhatsAppCallRequest) (*DisconnectWhatsAppCallResponse, error) {
	ctx = ctxsetters.WithPackageName(ctx, "livekit")
	ctx = ctxsetters.WithServiceName(ctx, "Connector")
	ctx = ctxsetters.WithMethodName(ctx, "DisconnectWhatsAppCall")
	caller := c.callDisconnectWhatsAppCall
	if c.interceptor != nil {
		caller = func(ctx context.Context, req *DisconnectWhatsAppCallRequest) (*DisconnectWhatsAppCallResponse, error) {
			resp, err := c.interceptor(
				func(ctx context.Context, req interface{}) (interface{}, error) {
					typedReq, ok := req.(*DisconnectWhatsAppCallRequest)
					if !ok {
						return nil, twirp.InternalError("failed type assertion req.(*DisconnectWhatsAppCallRequest) when calling interceptor")
					}
					return c.callDisconnectWhatsAppCall(ctx, typedReq)
				},
			)(ctx, req)
			if resp != nil {
				typedResp, ok := resp.(*DisconnectWhatsAppCallResponse)
				if !ok {
					return nil, twirp.InternalError("failed type assertion resp.(*DisconnectWhatsAppCallResponse) when calling interceptor")
				}
				return typedResp, err
			}
			return nil, err
		}
	}
	return caller(ctx, in)
}

func (c *connectorProtobufClient) callDisconnectWhatsAppCall(ctx context.Context, in *DisconnectWhatsAppCallRequest) (*DisconnectWhatsAppCallResponse, error) {
	out := new(DisconnectWhatsAppCallResponse)
	ctx, err := doProtobufRequest(ctx, c.client, c.opts.Hooks, c.urls[1], in, out)
	if err != nil {
		twerr, ok := err.(twirp.Error)
		if !ok {
			twerr = twirp.InternalErrorWith(err)
		}
		callClientError(ctx, c.opts.Hooks, twerr)
		return nil, err
	}

	callClientResponseReceived(ctx, c.opts.Hooks)

	return out, nil
}

func (c *connectorProtobufClient) ConnectWhatsAppCall(ctx context.Context, in *ConnectWhatsAppCallRequest) (*ConnectWhatsAppCallResponse, error) {
	ctx = ctxsetters.WithPackageName(ctx, "livekit")
	ctx = ctxsetters.WithServiceName(ctx, "Connector")
	ctx = ctxsetters.WithMethodName(ctx, "ConnectWhatsAppCall")
	caller := c.callConnectWhatsAppCall
	if c.interceptor != nil {
		caller = func(ctx context.Context, req *ConnectWhatsAppCallRequest) (*ConnectWhatsAppCallResponse, error) {
			resp, err := c.interceptor(
				func(ctx context.Context, req interface{}) (interface{}, error) {
					typedReq, ok := req.(*ConnectWhatsAppCallRequest)
					if !ok {
						return nil, twirp.InternalError("failed type assertion req.(*ConnectWhatsAppCallRequest) when calling interceptor")
					}
					return c.callConnectWhatsAppCall(ctx, typedReq)
				},
			)(ctx, req)
			if resp != nil {
				typedResp, ok := resp.(*ConnectWhatsAppCallResponse)
				if !ok {
					return nil, twirp.InternalError("failed type assertion resp.(*ConnectWhatsAppCallResponse) when calling interceptor")
				}
				return typedResp, err
			}
			return nil, err
		}
	}
	return caller(ctx, in)
}

func (c *connectorProtobufClient) callConnectWhatsAppCall(ctx context.Context, in *ConnectWhatsAppCallRequest) (*ConnectWhatsAppCallResponse, error) {
	out := new(ConnectWhatsAppCallResponse)
	ctx, err := doProtobufRequest(ctx, c.client, c.opts.Hooks, c.urls[2], in, out)
	if err != nil {
		twerr, ok := err.(twirp.Error)
		if !ok {
			twerr = twirp.InternalErrorWith(err)
		}
		callClientError(ctx, c.opts.Hooks, twerr)
		return nil, err
	}

	callClientResponseReceived(ctx, c.opts.Hooks)

	return out, nil
}

func (c *connectorProtobufClient) AcceptWhatsAppCall(ctx context.Context, in *AcceptWhatsAppCallRequest) (*AcceptWhatsAppCallResponse, error) {
	ctx = ctxsetters.WithPackageName(ctx, "livekit")
	ctx = ctxsetters.WithServiceName(ctx, "Connector")
	ctx = ctxsetters.WithMethodName(ctx, "AcceptWhatsAppCall")
	caller := c.callAcceptWhatsAppCall
	if c.interceptor != nil {
		caller = func(ctx context.Context, req *AcceptWhatsAppCallRequest) (*AcceptWhatsAppCallResponse, error) {
			resp, err := c.interceptor(
				func(ctx context.Context, req interface{}) (interface{}, error) {
					typedReq, ok := req.(*AcceptWhatsAppCallRequest)
					if !ok {
						return nil, twirp.InternalError("failed type assertion req.(*AcceptWhatsAppCallRequest) when calling interceptor")
					}
					return c.callAcceptWhatsAppCall(ctx, typedReq)
				},
			)(ctx, req)
			if resp != nil {
				typedResp, ok := resp.(*AcceptWhatsAppCallResponse)
				if !ok {
					return nil, twirp.InternalError("failed type assertion resp.(*AcceptWhatsAppCallResponse) when calling interceptor")
				}
				return typedResp, err
			}
			return nil, err
		}
	}
	return caller(ctx, in)
}

func (c *connectorProtobufClient) callAcceptWhatsAppCall(ctx context.Context, in *AcceptWhatsAppCallRequest) (*AcceptWhatsAppCallResponse, error) {
	out := new(AcceptWhatsAppCallResponse)
	ctx, err := doProtobufRequest(ctx, c.client, c.opts.Hooks, c.urls[3], in, out)
	if err != nil {
		twerr, ok := err.(twirp.Error)
		if !ok {
			twerr = twirp.InternalErrorWith(err)
		}
		callClientError(ctx, c.opts.Hooks, twerr)
		return nil, err
	}

	callClientResponseReceived(ctx, c.opts.Hooks)

	return out, nil
}

func (c *connectorProtobufClient) ConnectTwilioCall(ctx context.Context, in *ConnectTwilioCallRequest) (*ConnectTwilioCallResponse, error) {
	ctx = ctxsetters.WithPackageName(ctx, "livekit")
	ctx = ctxsetters.WithServiceName(ctx, "Connector")
	ctx = ctxsetters.WithMethodName(ctx, "ConnectTwilioCall")
	caller := c.callConnectTwilioCall
	if c.interceptor != nil {
		caller = func(ctx context.Context, req *ConnectTwilioCallRequest) (*ConnectTwilioCallResponse, error) {
			resp, err := c.interceptor(
				func(ctx context.Context, req interface{}) (interface{}, error) {
					typedReq, ok := req.(*ConnectTwilioCallRequest)
					if !ok {
						return nil, twirp.InternalError("failed type assertion req.(*ConnectTwilioCallRequest) when calling interceptor")
					}
					return c.callConnectTwilioCall(ctx, typedReq)
				},
			)(ctx, req)
			if resp != nil {
				typedResp, ok := resp.(*ConnectTwilioCallResponse)
				if !ok {
					return nil, twirp.InternalError("failed type assertion resp.(*ConnectTwilioCallResponse) when calling interceptor")
				}
				return typedResp, err
			}
			return nil, err
		}
	}
	return caller(ctx, in)
}

func (c *connectorProtobufClient) callConnectTwilioCall(ctx context.Context, in *ConnectTwilioCallRequest) (*ConnectTwilioCallResponse, error) {
	out := new(ConnectTwilioCallResponse)
	ctx, err := doProtobufRequest(ctx, c.client, c.opts.Hooks, c.urls[4], in, out)
	if err != nil {
		twerr, ok := err.(twirp.Error)
		if !ok {
			twerr = twirp.InternalErrorWith(err)
		}
		callClientError(ctx, c.opts.Hooks, twerr)
		return nil, err
	}

	callClientResponseReceived(ctx, c.opts.Hooks)

	return out, nil
}

// =====================
// Connector JSON Client
// =====================

type connectorJSONClient struct {
	client      HTTPClient
	urls        [5]string
	interceptor twirp.Interceptor
	opts        twirp.ClientOptions
}

// NewConnectorJSONClient creates a JSON client that implements the Connector interface.
// It communicates using JSON and can be configured with a custom HTTPClient.
func NewConnectorJSONClient(baseURL string, client HTTPClient, opts ...twirp.ClientOption) Connector {
	if c, ok := client.(*http.Client); ok {
		client = withoutRedirects(c)
	}

	clientOpts := twirp.ClientOptions{}
	for _, o := range opts {
		o(&clientOpts)
	}

	// Using ReadOpt allows backwards and forwards compatibility with new options in the future
	literalURLs := false
	_ = clientOpts.ReadOpt("literalURLs", &literalURLs)
	var pathPrefix string
	if ok := clientOpts.ReadOpt("pathPrefix", &pathPrefix); !ok {
		pathPrefix = "/twirp" // default prefix
	}

	// Build method URLs: <baseURL>[<prefix>]/<package>.<Service>/<Method>
	serviceURL := sanitizeBaseURL(baseURL)
	serviceURL += baseServicePath(pathPrefix, "livekit", "Connector")
	urls := [5]string{
		serviceURL + "DialWhatsAppCall",
		serviceURL + "DisconnectWhatsAppCall",
		serviceURL + "ConnectWhatsAppCall",
		serviceURL + "AcceptWhatsAppCall",
		serviceURL + "ConnectTwilioCall",
	}

	return &connectorJSONClient{
		client:      client,
		urls:        urls,
		interceptor: twirp.ChainInterceptors(clientOpts.Interceptors...),
		opts:        clientOpts,
	}
}

func (c *connectorJSONClient) DialWhatsAppCall(ctx context.Context, in *DialWhatsAppCallRequest) (*DialWhatsAppCallResponse, error) {
	ctx = ctxsetters.WithPackageName(ctx, "livekit")
	ctx = ctxsetters.WithServiceName(ctx, "Connector")
	ctx = ctxsetters.WithMethodName(ctx, "DialWhatsAppCall")
	caller := c.callDialWhatsAppCall
	if c.interceptor != nil {
		caller = func(ctx context.Context, req *DialWhatsAppCallRequest) (*DialWhatsAppCallResponse, error) {
			resp, err := c.interceptor(
				func(ctx context.Context, req interface{}) (interface{}, error) {
					typedReq, ok := req.(*DialWhatsAppCallRequest)
					if !ok {
						return nil, twirp.InternalError("failed type assertion req.(*DialWhatsAppCallRequest) when calling interceptor")
					}
					return c.callDialWhatsAppCall(ctx, typedReq)
				},
			)(ctx, req)
			if resp != nil {
				typedResp, ok := resp.(*DialWhatsAppCallResponse)
				if !ok {
					return nil, twirp.InternalError("failed type assertion resp.(*DialWhatsAppCallResponse) when calling interceptor")
				}
				return typedResp, err
			}
			return nil, err
		}
	}
	return caller(ctx, in)
}

func (c *connectorJSONClient) callDialWhatsAppCall(ctx context.Context, in *DialWhatsAppCallRequest) (*DialWhatsAppCallResponse, error) {
	out := new(DialWhatsAppCallResponse)
	ctx, err := doJSONRequest(ctx, c.client, c.opts.Hooks, c.urls[0], in, out)
	if err != nil {
		twerr, ok := err.(twirp.Error)
		if !ok {
			twerr = twirp.InternalErrorWith(err)
		}
		callClientError(ctx, c.opts.Hooks, twerr)
		return nil, err
	}

	callClientResponseReceived(ctx, c.opts.Hooks)

	return out, nil
}

func (c *connectorJSONClient) DisconnectWhatsAppCall(ctx context.Context, in *DisconnectWhatsAppCallRequest) (*DisconnectWhatsAppCallResponse, error) {
	ctx = ctxsetters.WithPackageName(ctx, "livekit")
	ctx = ctxsetters.WithServiceName(ctx, "Connector")
	ctx = ctxsetters.WithMethodName(ctx, "DisconnectWhatsAppCall")
	caller := c.callDisconnectWhatsAppCall
	if c.interceptor != nil {
		caller = func(ctx context.Context, req *DisconnectWhatsAppCallRequest) (*DisconnectWhatsAppCallResponse, error) {
			resp, err := c.interceptor(
				func(ctx context.Context, req interface{}) (interface{}, error) {
					typedReq, ok := req.(*DisconnectWhatsAppCallRequest)
					if !ok {
						return nil, twirp.InternalError("failed type assertion req.(*DisconnectWhatsAppCallRequest) when calling interceptor")
					}
					return c.callDisconnectWhatsAppCall(ctx, typedReq)
				},
			)(ctx, req)
			if resp != nil {
				typedResp, ok := resp.(*DisconnectWhatsAppCallResponse)
				if !ok {
					return nil, twirp.InternalError("failed type assertion resp.(*DisconnectWhatsAppCallResponse) when calling interceptor")
				}
				return typedResp, err
			}
			return nil, err
		}
	}
	return caller(ctx, in)
}

func (c *connectorJSONClient) callDisconnectWhatsAppCall(ctx context.Context, in *DisconnectWhatsAppCallRequest) (*DisconnectWhatsAppCallResponse, error) {
	out := new(DisconnectWhatsAppCallResponse)
	ctx, err := doJSONRequest(ctx, c.client, c.opts.Hooks, c.urls[1], in, out)
	if err != nil {
		twerr, ok := err.(twirp.Error)
		if !ok {
			twerr = twirp.InternalErrorWith(err)
		}
		callClientError(ctx, c.opts.Hooks, twerr)
		return nil, err
	}

	callClientResponseReceived(ctx, c.opts.Hooks)

	return out, nil
}

func (c *connectorJSONClient) ConnectWhatsAppCall(ctx context.Context, in *ConnectWhatsAppCallRequest) (*ConnectWhatsAppCallResponse, error) {
	ctx = ctxsetters.WithPackageName(ctx, "livekit")
	ctx = ctxsetters.WithServiceName(ctx, "Connector")
	ctx = ctxsetters.WithMethodName(ctx, "ConnectWhatsAppCall")
	caller := c.callConnectWhatsAppCall
	if c.interceptor != nil {
		caller = func(ctx context.Context, req *ConnectWhatsAppCallRequest) (*ConnectWhatsAppCallResponse, error) {
			resp, err := c.interceptor(
				func(ctx context.Context, req interface{}) (interface{}, error) {
					typedReq, ok := req.(*ConnectWhatsAppCallRequest)
					if !ok {
						return nil, twirp.InternalError("failed type assertion req.(*ConnectWhatsAppCallRequest) when calling interceptor")
					}
					return c.callConnectWhatsAppCall(ctx, typedReq)
				},
			)(ctx, req)
			if resp != nil {
				typedResp, ok := resp.(*ConnectWhatsAppCallResponse)
				if !ok {
					return nil, twirp.InternalError("failed type assertion resp.(*ConnectWhatsAppCallResponse) when calling interceptor")
				}
				return typedResp, err
			}
			return nil, err
		}
	}
	return caller(ctx, in)
}

func (c *connectorJSONClient) callConnectWhatsAppCall(ctx context.Context, in *ConnectWhatsAppCallRequest) (*ConnectWhatsAppCallResponse, error) {
	out := new(ConnectWhatsAppCallResponse)
	ctx, err := doJSONRequest(ctx, c.client, c.opts.Hooks, c.urls[2], in, out)
	if err != nil {
		twerr, ok := err.(twirp.Error)
		if !ok {
			twerr = twirp.InternalErrorWith(err)
		}
		callClientError(ctx, c.opts.Hooks, twerr)
		return nil, err
	}

	callClientResponseReceived(ctx, c.opts.Hooks)

	return out, nil
}

func (c *connectorJSONClient) AcceptWhatsAppCall(ctx context.Context, in *AcceptWhatsAppCallRequest) (*AcceptWhatsAppCallResponse, error) {
	ctx = ctxsetters.WithPackageName(ctx, "livekit")
	ctx = ctxsetters.WithServiceName(ctx, "Connector")
	ctx = ctxsetters.WithMethodName(ctx, "AcceptWhatsAppCall")
	caller := c.callAcceptWhatsAppCall
	if c.interceptor != nil {
		caller = func(ctx context.Context, req *AcceptWhatsAppCallRequest) (*AcceptWhatsAppCallResponse, error) {
			resp, err := c.interceptor(
				func(ctx context.Context, req interface{}) (interface{}, error) {
					typedReq, ok := req.(*AcceptWhatsAppCallRequest)
					if !ok {
						return nil, twirp.InternalError("failed type assertion req.(*AcceptWhatsAppCallRequest) when calling interceptor")
					}
					return c.callAcceptWhatsAppCall(ctx, typedReq)
				},
			)(ctx, req)
			if resp != nil {
				typedResp, ok := resp.(*AcceptWhatsAppCallResponse)
				if !ok {
					return nil, twirp.InternalError("failed type assertion resp.(*AcceptWhatsAppCallResponse) when calling interceptor")
				}
				return typedResp, err
			}
			return nil, err
		}
	}
	return caller(ctx, in)
}

func (c *connectorJSONClient) callAcceptWhatsAppCall(ctx context.Context, in *AcceptWhatsAppCallRequest) (*AcceptWhatsAppCallResponse, error) {
	out := new(AcceptWhatsAppCallResponse)
	ctx, err := doJSONRequest(ctx, c.client, c.opts.Hooks, c.urls[3], in, out)
	if err != nil {
		twerr, ok := err.(twirp.Error)
		if !ok {
			twerr = twirp.InternalErrorWith(err)
		}
		callClientError(ctx, c.opts.Hooks, twerr)
		return nil, err
	}

	callClientResponseReceived(ctx, c.opts.Hooks)

	return out, nil
}

func (c *connectorJSONClient) ConnectTwilioCall(ctx context.Context, in *ConnectTwilioCallRequest) (*ConnectTwilioCallResponse, error) {
	ctx = ctxsetters.WithPackageName(ctx, "livekit")
	ctx = ctxsetters.WithServiceName(ctx, "Connector")
	ctx = ctxsetters.WithMethodName(ctx, "ConnectTwilioCall")
	caller := c.callConnectTwilioCall
	if c.interceptor != nil {
		caller = func(ctx context.Context, req *ConnectTwilioCallRequest) (*ConnectTwilioCallResponse, error) {
			resp, err := c.interceptor(
				func(ctx context.Context, req interface{}) (interface{}, error) {
					typedReq, ok := req.(*ConnectTwilioCallRequest)
					if !ok {
						return nil, twirp.InternalError("failed type assertion req.(*ConnectTwilioCallRequest) when calling interceptor")
					}
					return c.callConnectTwilioCall(ctx, typedReq)
				},
			)(ctx, req)
			if resp != nil {
				typedResp, ok := resp.(*ConnectTwilioCallResponse)
				if !ok {
					return nil, twirp.InternalError("failed type assertion resp.(*ConnectTwilioCallResponse) when calling interceptor")
				}
				return typedResp, err
			}
			return nil, err
		}
	}
	return caller(ctx, in)
}

func (c *connectorJSONClient) callConnectTwilioCall(ctx context.Context, in *ConnectTwilioCallRequest) (*ConnectTwilioCallResponse, error) {
	out := new(ConnectTwilioCallResponse)
	ctx, err := doJSONRequest(ctx, c.client, c.opts.Hooks, c.urls[4], in, out)
	if err != nil {
		twerr, ok := err.(twirp.Error)
		if !ok {
			twerr = twirp.InternalErrorWith(err)
		}
		callClientError(ctx, c.opts.Hooks, twerr)
		return nil, err
	}

	callClientResponseReceived(ctx, c.opts.Hooks)

	return out, nil
}

// ========================
// Connector Server Handler
// ========================

type connectorServer struct {
	Connector
	interceptor      twirp.Interceptor
	hooks            *twirp.ServerHooks
	pathPrefix       string // prefix for routing
	jsonSkipDefaults bool   // do not include unpopulated fields (default values) in the response
	jsonCamelCase    bool   // JSON fields are serialized as lowerCamelCase rather than keeping the original proto names
}

// NewConnectorServer builds a TwirpServer that can be used as an http.Handler to handle
// HTTP requests that are routed to the right method in the provided svc implementation.
// The opts are twirp.ServerOption modifiers, for example twirp.WithServerHooks(hooks).
func NewConnectorServer(svc Connector, opts ...interface{}) TwirpServer {
	serverOpts := newServerOpts(opts)

	// Using ReadOpt allows backwards and forwards compatibility with new options in the future
	jsonSkipDefaults := false
	_ = serverOpts.ReadOpt("jsonSkipDefaults", &jsonSkipDefaults)
	jsonCamelCase := false
	_ = serverOpts.ReadOpt("jsonCamelCase", &jsonCamelCase)
	var pathPrefix string
	if ok := serverOpts.ReadOpt("pathPrefix", &pathPrefix); !ok {
		pathPrefix = "/twirp" // default prefix
	}

	return &connectorServer{
		Connector:        svc,
		hooks:            serverOpts.Hooks,
		interceptor:      twirp.ChainInterceptors(serverOpts.Interceptors...),
		pathPrefix:       pathPrefix,
		jsonSkipDefaults: jsonSkipDefaults,
		jsonCamelCase:    jsonCamelCase,
	}
}

// writeError writes an HTTP response with a valid Twirp error format, and triggers hooks.
// If err is not a twirp.Error, it will get wrapped with twirp.InternalErrorWith(err)
func (s *connectorServer) writeError(ctx context.Context, resp http.ResponseWriter, err error) {
	writeError(ctx, resp, err, s.hooks)
}

// handleRequestBodyError is used to handle error when the twirp server cannot read request
func (s *connectorServer) handleRequestBodyError(ctx context.Context, resp http.ResponseWriter, msg string, err error) {
	if context.Canceled == ctx.Err() {
		s.writeError(ctx, resp, twirp.NewError(twirp.Canceled, "failed to read request: context canceled"))
		return
	}
	if context.DeadlineExceeded == ctx.Err() {
		s.writeError(ctx, resp, twirp.NewError(twirp.DeadlineExceeded, "failed to read request: deadline exceeded"))
		return
	}
	s.writeError(ctx, resp, twirp.WrapError(malformedRequestError(msg), err))
}

// ConnectorPathPrefix is a convenience constant that may identify URL paths.
// Should be used with caution, it only matches routes generated by Twirp Go clients,
// with the default "/twirp" prefix and default CamelCase service and method names.
// More info: https://twitchtv.github.io/twirp/docs/routing.html
const ConnectorPathPrefix = "/twirp/livekit.Connector/"

func (s *connectorServer) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
	ctx := req.Context()
	ctx = ctxsetters.WithPackageName(ctx, "livekit")
	ctx = ctxsetters.WithServiceName(ctx, "Connector")
	ctx = ctxsetters.WithResponseWriter(ctx, resp)

	var err error
	ctx, err = callRequestReceived(ctx, s.hooks)
	if err != nil {
		s.writeError(ctx, resp, err)
		return
	}

	if req.Method != "POST" {
		msg := fmt.Sprintf("unsupported method %q (only POST is allowed)", req.Method)
		s.writeError(ctx, resp, badRouteError(msg, req.Method, req.URL.Path))
		return
	}

	// Verify path format: [<prefix>]/<package>.<Service>/<Method>
	prefix, pkgService, method := parseTwirpPath(req.URL.Path)
	if pkgService != "livekit.Connector" {
		msg := fmt.Sprintf("no handler for path %q", req.URL.Path)
		s.writeError(ctx, resp, badRouteError(msg, req.Method, req.URL.Path))
		return
	}
	if prefix != s.pathPrefix {
		msg := fmt.Sprintf("invalid path prefix %q, expected %q, on path %q", prefix, s.pathPrefix, req.URL.Path)
		s.writeError(ctx, resp, badRouteError(msg, req.Method, req.URL.Path))
		return
	}

	switch method {
	case "DialWhatsAppCall":
		s.serveDialWhatsAppCall(ctx, resp, req)
		return
	case "DisconnectWhatsAppCall":
		s.serveDisconnectWhatsAppCall(ctx, resp, req)
		return
	case "ConnectWhatsAppCall":
		s.serveConnectWhatsAppCall(ctx, resp, req)
		return
	case "AcceptWhatsAppCall":
		s.serveAcceptWhatsAppCall(ctx, resp, req)
		return
	case "ConnectTwilioCall":
		s.serveConnectTwilioCall(ctx, resp, req)
		return
	default:
		msg := fmt.Sprintf("no handler for path %q", req.URL.Path)
		s.writeError(ctx, resp, badRouteError(msg, req.Method, req.URL.Path))
		return
	}
}

func (s *connectorServer) serveDialWhatsAppCall(ctx context.Context, resp http.ResponseWriter, req *http.Request) {
	header := req.Header.Get("Content-Type")
	i := strings.Index(header, ";")
	if i == -1 {
		i = len(header)
	}
	switch strings.TrimSpace(strings.ToLower(header[:i])) {
	case "application/json":
		s.serveDialWhatsAppCallJSON(ctx, resp, req)
	case "application/protobuf":
		s.serveDialWhatsAppCallProtobuf(ctx, resp, req)
	default:
		msg := fmt.Sprintf("unexpected Content-Type: %q", req.Header.Get("Content-Type"))
		twerr := badRouteError(msg, req.Method, req.URL.Path)
		s.writeError(ctx, resp, twerr)
	}
}

func (s *connectorServer) serveDialWhatsAppCallJSON(ctx context.Context, resp http.ResponseWriter, req *http.Request) {
	var err error
	ctx = ctxsetters.WithMethodName(ctx, "DialWhatsAppCall")
	ctx, err = callRequestRouted(ctx, s.hooks)
	if err != nil {
		s.writeError(ctx, resp, err)
		return
	}

	d := json.NewDecoder(req.Body)
	rawReqBody := json.RawMessage{}
	if err := d.Decode(&rawReqBody); err != nil {
		s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err)
		return
	}
	reqContent := new(DialWhatsAppCallRequest)
	unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true}
	if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil {
		s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err)
		return
	}

	handler := s.Connector.DialWhatsAppCall
	if s.interceptor != nil {
		handler = func(ctx context.Context, req *DialWhatsAppCallRequest) (*DialWhatsAppCallResponse, error) {
			resp, err := s.interceptor(
				func(ctx context.Context, req interface{}) (interface{}, error) {
					typedReq, ok := req.(*DialWhatsAppCallRequest)
					if !ok {
						return nil, twirp.InternalError("failed type assertion req.(*DialWhatsAppCallRequest) when calling interceptor")
					}
					return s.Connector.DialWhatsAppCall(ctx, typedReq)
				},
			)(ctx, req)
			if resp != nil {
				typedResp, ok := resp.(*DialWhatsAppCallResponse)
				if !ok {
					return nil, twirp.InternalError("failed type assertion resp.(*DialWhatsAppCallResponse) when calling interceptor")
				}
				return typedResp, err
			}
			return nil, err
		}
	}

	// Call service method
	var respContent *DialWhatsAppCallResponse
	func() {
		defer ensurePanicResponses(ctx, resp, s.hooks)
		respContent, err = handler(ctx, reqContent)
	}()

	if err != nil {
		s.writeError(ctx, resp, err)
		return
	}
	if respContent == nil {
		s.writeError(ctx, resp, twirp.InternalError("received a nil *DialWhatsAppCallResponse and nil error while calling DialWhatsAppCall. nil responses are not supported"))
		return
	}

	ctx = callResponsePrepared(ctx, s.hooks)

	marshaler := &protojson.MarshalOptions{UseProtoNames: !s.jsonCamelCase, EmitUnpopulated: !s.jsonSkipDefaults}
	respBytes, err := marshaler.Marshal(respContent)
	if err != nil {
		s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response"))
		return
	}

	ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK)
	resp.Header().Set("Content-Type", "application/json")
	resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes)))
	resp.WriteHeader(http.StatusOK)

	if n, err := resp.Write(respBytes); err != nil {
		msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error())
		twerr := twirp.NewError(twirp.Unknown, msg)
		ctx = callError(ctx, s.hooks, twerr)
	}
	callResponseSent(ctx, s.hooks)
}

func (s *connectorServer) serveDialWhatsAppCallProtobuf(ctx context.Context, resp http.ResponseWriter, req *http.Request) {
	var err error
	ctx = ctxsetters.WithMethodName(ctx, "DialWhatsAppCall")
	ctx, err = callRequestRouted(ctx, s.hooks)
	if err != nil {
		s.writeError(ctx, resp, err)
		return
	}

	buf, err := io.ReadAll(req.Body)
	if err != nil {
		s.handleRequestBodyError(ctx, resp, "failed to read request body", err)
		return
	}
	reqContent := new(DialWhatsAppCallRequest)
	if err = proto.Unmarshal(buf, reqContent); err != nil {
		s.writeError(ctx, resp, malformedRequestError("the protobuf request could not be decoded"))
		return
	}

	handler := s.Connector.DialWhatsAppCall
	if s.interceptor != nil {
		handler = func(ctx context.Context, req *DialWhatsAppCallRequest) (*DialWhatsAppCallResponse, error) {
			resp, err := s.interceptor(
				func(ctx context.Context, req interface{}) (interface{}, error) {
					typedReq, ok := req.(*DialWhatsAppCallRequest)
					if !ok {
						return nil, twirp.InternalError("failed type assertion req.(*DialWhatsAppCallRequest) when calling interceptor")
					}
					return s.Connector.DialWhatsAppCall(ctx, typedReq)
				},
			)(ctx, req)
			if resp != nil {
				typedResp, ok := resp.(*DialWhatsAppCallResponse)
				if !ok {
					return nil, twirp.InternalError("failed type assertion resp.(*DialWhatsAppCallResponse) when calling interceptor")
				}
				return typedResp, err
			}
			return nil, err
		}
	}

	// Call service method
	var respContent *DialWhatsAppCallResponse
	func() {
		defer ensurePanicResponses(ctx, resp, s.hooks)
		respContent, err = handler(ctx, reqContent)
	}()

	if err != nil {
		s.writeError(ctx, resp, err)
		return
	}
	if respContent == nil {
		s.writeError(ctx, resp, twirp.InternalError("received a nil *DialWhatsAppCallResponse and nil error while calling DialWhatsAppCall. nil responses are not supported"))
		return
	}

	ctx = callResponsePrepared(ctx, s.hooks)

	respBytes, err := proto.Marshal(respContent)
	if err != nil {
		s.writeError(ctx, resp, wrapInternal(err, "failed to marshal proto response"))
		return
	}

	ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK)
	resp.Header().Set("Content-Type", "application/protobuf")
	resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes)))
	resp.WriteHeader(http.StatusOK)
	if n, err := resp.Write(respBytes); err != nil {
		msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error())
		twerr := twirp.NewError(twirp.Unknown, msg)
		ctx = callError(ctx, s.hooks, twerr)
	}
	callResponseSent(ctx, s.hooks)
}

func (s *connectorServer) serveDisconnectWhatsAppCall(ctx context.Context, resp http.ResponseWriter, req *http.Request) {
	header := req.Header.Get("Content-Type")
	i := strings.Index(header, ";")
	if i == -1 {
		i = len(header)
	}
	switch strings.TrimSpace(strings.ToLower(header[:i])) {
	case "application/json":
		s.serveDisconnectWhatsAppCallJSON(ctx, resp, req)
	case "application/protobuf":
		s.serveDisconnectWhatsAppCallProtobuf(ctx, resp, req)
	default:
		msg := fmt.Sprintf("unexpected Content-Type: %q", req.Header.Get("Content-Type"))
		twerr := badRouteError(msg, req.Method, req.URL.Path)
		s.writeError(ctx, resp, twerr)
	}
}

func (s *connectorServer) serveDisconnectWhatsAppCallJSON(ctx context.Context, resp http.ResponseWriter, req *http.Request) {
	var err error
	ctx = ctxsetters.WithMethodName(ctx, "DisconnectWhatsAppCall")
	ctx, err = callRequestRouted(ctx, s.hooks)
	if err != nil {
		s.writeError(ctx, resp, err)
		return
	}

	d := json.NewDecoder(req.Body)
	rawReqBody := json.RawMessage{}
	if err := d.Decode(&rawReqBody); err != nil {
		s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err)
		return
	}
	reqContent := new(DisconnectWhatsAppCallRequest)
	unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true}
	if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil {
		s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err)
		return
	}

	handler := s.Connector.DisconnectWhatsAppCall
	if s.interceptor != nil {
		handler = func(ctx context.Context, req *DisconnectWhatsAppCallRequest) (*DisconnectWhatsAppCallResponse, error) {
			resp, err := s.interceptor(
				func(ctx context.Context, req interface{}) (interface{}, error) {
					typedReq, ok := req.(*DisconnectWhatsAppCallRequest)
					if !ok {
						return nil, twirp.InternalError("failed type assertion req.(*DisconnectWhatsAppCallRequest) when calling interceptor")
					}
					return s.Connector.DisconnectWhatsAppCall(ctx, typedReq)
				},
			)(ctx, req)
			if resp != nil {
				typedResp, ok := resp.(*DisconnectWhatsAppCallResponse)
				if !ok {
					return nil, twirp.InternalError("failed type assertion resp.(*DisconnectWhatsAppCallResponse) when calling interceptor")
				}
				return typedResp, err
			}
			return nil, err
		}
	}

	// Call service method
	var respContent *DisconnectWhatsAppCallResponse
	func() {
		defer ensurePanicResponses(ctx, resp, s.hooks)
		respContent, err = handler(ctx, reqContent)
	}()

	if err != nil {
		s.writeError(ctx, resp, err)
		return
	}
	if respContent == nil {
		s.writeError(ctx, resp, twirp.InternalError("received a nil *DisconnectWhatsAppCallResponse and nil error while calling DisconnectWhatsAppCall. nil responses are not supported"))
		return
	}

	ctx = callResponsePrepared(ctx, s.hooks)

	marshaler := &protojson.MarshalOptions{UseProtoNames: !s.jsonCamelCase, EmitUnpopulated: !s.jsonSkipDefaults}
	respBytes, err := marshaler.Marshal(respContent)
	if err != nil {
		s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response"))
		return
	}

	ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK)
	resp.Header().Set("Content-Type", "application/json")
	resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes)))
	resp.WriteHeader(http.StatusOK)

	if n, err := resp.Write(respBytes); err != nil {
		msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error())
		twerr := twirp.NewError(twirp.Unknown, msg)
		ctx = callError(ctx, s.hooks, twerr)
	}
	callResponseSent(ctx, s.hooks)
}

func (s *connectorServer) serveDisconnectWhatsAppCallProtobuf(ctx context.Context, resp http.ResponseWriter, req *http.Request) {
	var err error
	ctx = ctxsetters.WithMethodName(ctx, "DisconnectWhatsAppCall")
	ctx, err = callRequestRouted(ctx, s.hooks)
	if err != nil {
		s.writeError(ctx, resp, err)
		return
	}

	buf, err := io.ReadAll(req.Body)
	if err != nil {
		s.handleRequestBodyError(ctx, resp, "failed to read request body", err)
		return
	}
	reqContent := new(DisconnectWhatsAppCallRequest)
	if err = proto.Unmarshal(buf, reqContent); err != nil {
		s.writeError(ctx, resp, malformedRequestError("the protobuf request could not be decoded"))
		return
	}

	handler := s.Connector.DisconnectWhatsAppCall
	if s.interceptor != nil {
		handler = func(ctx context.Context, req *DisconnectWhatsAppCallRequest) (*DisconnectWhatsAppCallResponse, error) {
			resp, err := s.interceptor(
				func(ctx context.Context, req interface{}) (interface{}, error) {
					typedReq, ok := req.(*DisconnectWhatsAppCallRequest)
					if !ok {
						return nil, twirp.InternalError("failed type assertion req.(*DisconnectWhatsAppCallRequest) when calling interceptor")
					}
					return s.Connector.DisconnectWhatsAppCall(ctx, typedReq)
				},
			)(ctx, req)
			if resp != nil {
				typedResp, ok := resp.(*DisconnectWhatsAppCallResponse)
				if !ok {
					return nil, twirp.InternalError("failed type assertion resp.(*DisconnectWhatsAppCallResponse) when calling interceptor")
				}
				return typedResp, err
			}
			return nil, err
		}
	}

	// Call service method
	var respContent *DisconnectWhatsAppCallResponse
	func() {
		defer ensurePanicResponses(ctx, resp, s.hooks)
		respContent, err = handler(ctx, reqContent)
	}()

	if err != nil {
		s.writeError(ctx, resp, err)
		return
	}
	if respContent == nil {
		s.writeError(ctx, resp, twirp.InternalError("received a nil *DisconnectWhatsAppCallResponse and nil error while calling DisconnectWhatsAppCall. nil responses are not supported"))
		return
	}

	ctx = callResponsePrepared(ctx, s.hooks)

	respBytes, err := proto.Marshal(respContent)
	if err != nil {
		s.writeError(ctx, resp, wrapInternal(err, "failed to marshal proto response"))
		return
	}

	ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK)
	resp.Header().Set("Content-Type", "application/protobuf")
	resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes)))
	resp.WriteHeader(http.StatusOK)
	if n, err := resp.Write(respBytes); err != nil {
		msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error())
		twerr := twirp.NewError(twirp.Unknown, msg)
		ctx = callError(ctx, s.hooks, twerr)
	}
	callResponseSent(ctx, s.hooks)
}

func (s *connectorServer) serveConnectWhatsAppCall(ctx context.Context, resp http.ResponseWriter, req *http.Request) {
	header := req.Header.Get("Content-Type")
	i := strings.Index(header, ";")
	if i == -1 {
		i = len(header)
	}
	switch strings.TrimSpace(strings.ToLower(header[:i])) {
	case "application/json":
		s.serveConnectWhatsAppCallJSON(ctx, resp, req)
	case "application/protobuf":
		s.serveConnectWhatsAppCallProtobuf(ctx, resp, req)
	default:
		msg := fmt.Sprintf("unexpected Content-Type: %q", req.Header.Get("Content-Type"))
		twerr := badRouteError(msg, req.Method, req.URL.Path)
		s.writeError(ctx, resp, twerr)
	}
}

func (s *connectorServer) serveConnectWhatsAppCallJSON(ctx context.Context, resp http.ResponseWriter, req *http.Request) {
	var err error
	ctx = ctxsetters.WithMethodName(ctx, "ConnectWhatsAppCall")
	ctx, err = callRequestRouted(ctx, s.hooks)
	if err != nil {
		s.writeError(ctx, resp, err)
		return
	}

	d := json.NewDecoder(req.Body)
	rawReqBody := json.RawMessage{}
	if err := d.Decode(&rawReqBody); err != nil {
		s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err)
		return
	}
	reqContent := new(ConnectWhatsAppCallRequest)
	unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true}
	if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil {
		s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err)
		return
	}

	handler := s.Connector.ConnectWhatsAppCall
	if s.interceptor != nil {
		handler = func(ctx context.Context, req *ConnectWhatsAppCallRequest) (*ConnectWhatsAppCallResponse, error) {
			resp, err := s.interceptor(
				func(ctx context.Context, req interface{}) (interface{}, error) {
					typedReq, ok := req.(*ConnectWhatsAppCallRequest)
					if !ok {
						return nil, twirp.InternalError("failed type assertion req.(*ConnectWhatsAppCallRequest) when calling interceptor")
					}
					return s.Connector.ConnectWhatsAppCall(ctx, typedReq)
				},
			)(ctx, req)
			if resp != nil {
				typedResp, ok := resp.(*ConnectWhatsAppCallResponse)
				if !ok {
					return nil, twirp.InternalError("failed type assertion resp.(*ConnectWhatsAppCallResponse) when calling interceptor")
				}
				return typedResp, err
			}
			return nil, err
		}
	}

	// Call service method
	var respContent *ConnectWhatsAppCallResponse
	func() {
		defer ensurePanicResponses(ctx, resp, s.hooks)
		respContent, err = handler(ctx, reqContent)
	}()

	if err != nil {
		s.writeError(ctx, resp, err)
		return
	}
	if respContent == nil {
		s.writeError(ctx, resp, twirp.InternalError("received a nil *ConnectWhatsAppCallResponse and nil error while calling ConnectWhatsAppCall. nil responses are not supported"))
		return
	}

	ctx = callResponsePrepared(ctx, s.hooks)

	marshaler := &protojson.MarshalOptions{UseProtoNames: !s.jsonCamelCase, EmitUnpopulated: !s.jsonSkipDefaults}
	respBytes, err := marshaler.Marshal(respContent)
	if err != nil {
		s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response"))
		return
	}

	ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK)
	resp.Header().Set("Content-Type", "application/json")
	resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes)))
	resp.WriteHeader(http.StatusOK)

	if n, err := resp.Write(respBytes); err != nil {
		msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error())
		twerr := twirp.NewError(twirp.Unknown, msg)
		ctx = callError(ctx, s.hooks, twerr)
	}
	callResponseSent(ctx, s.hooks)
}

func (s *connectorServer) serveConnectWhatsAppCallProtobuf(ctx context.Context, resp http.ResponseWriter, req *http.Request) {
	var err error
	ctx = ctxsetters.WithMethodName(ctx, "ConnectWhatsAppCall")
	ctx, err = callRequestRouted(ctx, s.hooks)
	if err != nil {
		s.writeError(ctx, resp, err)
		return
	}

	buf, err := io.ReadAll(req.Body)
	if err != nil {
		s.handleRequestBodyError(ctx, resp, "failed to read request body", err)
		return
	}
	reqContent := new(ConnectWhatsAppCallRequest)
	if err = proto.Unmarshal(buf, reqContent); err != nil {
		s.writeError(ctx, resp, malformedRequestError("the protobuf request could not be decoded"))
		return
	}

	handler := s.Connector.ConnectWhatsAppCall
	if s.interceptor != nil {
		handler = func(ctx context.Context, req *ConnectWhatsAppCallRequest) (*ConnectWhatsAppCallResponse, error) {
			resp, err := s.interceptor(
				func(ctx context.Context, req interface{}) (interface{}, error) {
					typedReq, ok := req.(*ConnectWhatsAppCallRequest)
					if !ok {
						return nil, twirp.InternalError("failed type assertion req.(*ConnectWhatsAppCallRequest) when calling interceptor")
					}
					return s.Connector.ConnectWhatsAppCall(ctx, typedReq)
				},
			)(ctx, req)
			if resp != nil {
				typedResp, ok := resp.(*ConnectWhatsAppCallResponse)
				if !ok {
					return nil, twirp.InternalError("failed type assertion resp.(*ConnectWhatsAppCallResponse) when calling interceptor")
				}
				return typedResp, err
			}
			return nil, err
		}
	}

	// Call service method
	var respContent *ConnectWhatsAppCallResponse
	func() {
		defer ensurePanicResponses(ctx, resp, s.hooks)
		respContent, err = handler(ctx, reqContent)
	}()

	if err != nil {
		s.writeError(ctx, resp, err)
		return
	}
	if respContent == nil {
		s.writeError(ctx, resp, twirp.InternalError("received a nil *ConnectWhatsAppCallResponse and nil error while calling ConnectWhatsAppCall. nil responses are not supported"))
		return
	}

	ctx = callResponsePrepared(ctx, s.hooks)

	respBytes, err := proto.Marshal(respContent)
	if err != nil {
		s.writeError(ctx, resp, wrapInternal(err, "failed to marshal proto response"))
		return
	}

	ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK)
	resp.Header().Set("Content-Type", "application/protobuf")
	resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes)))
	resp.WriteHeader(http.StatusOK)
	if n, err := resp.Write(respBytes); err != nil {
		msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error())
		twerr := twirp.NewError(twirp.Unknown, msg)
		ctx = callError(ctx, s.hooks, twerr)
	}
	callResponseSent(ctx, s.hooks)
}

func (s *connectorServer) serveAcceptWhatsAppCall(ctx context.Context, resp http.ResponseWriter, req *http.Request) {
	header := req.Header.Get("Content-Type")
	i := strings.Index(header, ";")
	if i == -1 {
		i = len(header)
	}
	switch strings.TrimSpace(strings.ToLower(header[:i])) {
	case "application/json":
		s.serveAcceptWhatsAppCallJSON(ctx, resp, req)
	case "application/protobuf":
		s.serveAcceptWhatsAppCallProtobuf(ctx, resp, req)
	default:
		msg := fmt.Sprintf("unexpected Content-Type: %q", req.Header.Get("Content-Type"))
		twerr := badRouteError(msg, req.Method, req.URL.Path)
		s.writeError(ctx, resp, twerr)
	}
}

func (s *connectorServer) serveAcceptWhatsAppCallJSON(ctx context.Context, resp http.ResponseWriter, req *http.Request) {
	var err error
	ctx = ctxsetters.WithMethodName(ctx, "AcceptWhatsAppCall")
	ctx, err = callRequestRouted(ctx, s.hooks)
	if err != nil {
		s.writeError(ctx, resp, err)
		return
	}

	d := json.NewDecoder(req.Body)
	rawReqBody := json.RawMessage{}
	if err := d.Decode(&rawReqBody); err != nil {
		s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err)
		return
	}
	reqContent := new(AcceptWhatsAppCallRequest)
	unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true}
	if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil {
		s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err)
		return
	}

	handler := s.Connector.AcceptWhatsAppCall
	if s.interceptor != nil {
		handler = func(ctx context.Context, req *AcceptWhatsAppCallRequest) (*AcceptWhatsAppCallResponse, error) {
			resp, err := s.interceptor(
				func(ctx context.Context, req interface{}) (interface{}, error) {
					typedReq, ok := req.(*AcceptWhatsAppCallRequest)
					if !ok {
						return nil, twirp.InternalError("failed type assertion req.(*AcceptWhatsAppCallRequest) when calling interceptor")
					}
					return s.Connector.AcceptWhatsAppCall(ctx, typedReq)
				},
			)(ctx, req)
			if resp != nil {
				typedResp, ok := resp.(*AcceptWhatsAppCallResponse)
				if !ok {
					return nil, twirp.InternalError("failed type assertion resp.(*AcceptWhatsAppCallResponse) when calling interceptor")
				}
				return typedResp, err
			}
			return nil, err
		}
	}

	// Call service method
	var respContent *AcceptWhatsAppCallResponse
	func() {
		defer ensurePanicResponses(ctx, resp, s.hooks)
		respContent, err = handler(ctx, reqContent)
	}()

	if err != nil {
		s.writeError(ctx, resp, err)
		return
	}
	if respContent == nil {
		s.writeError(ctx, resp, twirp.InternalError("received a nil *AcceptWhatsAppCallResponse and nil error while calling AcceptWhatsAppCall. nil responses are not supported"))
		return
	}

	ctx = callResponsePrepared(ctx, s.hooks)

	marshaler := &protojson.MarshalOptions{UseProtoNames: !s.jsonCamelCase, EmitUnpopulated: !s.jsonSkipDefaults}
	respBytes, err := marshaler.Marshal(respContent)
	if err != nil {
		s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response"))
		return
	}

	ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK)
	resp.Header().Set("Content-Type", "application/json")
	resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes)))
	resp.WriteHeader(http.StatusOK)

	if n, err := resp.Write(respBytes); err != nil {
		msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error())
		twerr := twirp.NewError(twirp.Unknown, msg)
		ctx = callError(ctx, s.hooks, twerr)
	}
	callResponseSent(ctx, s.hooks)
}

func (s *connectorServer) serveAcceptWhatsAppCallProtobuf(ctx context.Context, resp http.ResponseWriter, req *http.Request) {
	var err error
	ctx = ctxsetters.WithMethodName(ctx, "AcceptWhatsAppCall")
	ctx, err = callRequestRouted(ctx, s.hooks)
	if err != nil {
		s.writeError(ctx, resp, err)
		return
	}

	buf, err := io.ReadAll(req.Body)
	if err != nil {
		s.handleRequestBodyError(ctx, resp, "failed to read request body", err)
		return
	}
	reqContent := new(AcceptWhatsAppCallRequest)
	if err = proto.Unmarshal(buf, reqContent); err != nil {
		s.writeError(ctx, resp, malformedRequestError("the protobuf request could not be decoded"))
		return
	}

	handler := s.Connector.AcceptWhatsAppCall
	if s.interceptor != nil {
		handler = func(ctx context.Context, req *AcceptWhatsAppCallRequest) (*AcceptWhatsAppCallResponse, error) {
			resp, err := s.interceptor(
				func(ctx context.Context, req interface{}) (interface{}, error) {
					typedReq, ok := req.(*AcceptWhatsAppCallRequest)
					if !ok {
						return nil, twirp.InternalError("failed type assertion req.(*AcceptWhatsAppCallRequest) when calling interceptor")
					}
					return s.Connector.AcceptWhatsAppCall(ctx, typedReq)
				},
			)(ctx, req)
			if resp != nil {
				typedResp, ok := resp.(*AcceptWhatsAppCallResponse)
				if !ok {
					return nil, twirp.InternalError("failed type assertion resp.(*AcceptWhatsAppCallResponse) when calling interceptor")
				}
				return typedResp, err
			}
			return nil, err
		}
	}

	// Call service method
	var respContent *AcceptWhatsAppCallResponse
	func() {
		defer ensurePanicResponses(ctx, resp, s.hooks)
		respContent, err = handler(ctx, reqContent)
	}()

	if err != nil {
		s.writeError(ctx, resp, err)
		return
	}
	if respContent == nil {
		s.writeError(ctx, resp, twirp.InternalError("received a nil *AcceptWhatsAppCallResponse and nil error while calling AcceptWhatsAppCall. nil responses are not supported"))
		return
	}

	ctx = callResponsePrepared(ctx, s.hooks)

	respBytes, err := proto.Marshal(respContent)
	if err != nil {
		s.writeError(ctx, resp, wrapInternal(err, "failed to marshal proto response"))
		return
	}

	ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK)
	resp.Header().Set("Content-Type", "application/protobuf")
	resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes)))
	resp.WriteHeader(http.StatusOK)
	if n, err := resp.Write(respBytes); err != nil {
		msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error())
		twerr := twirp.NewError(twirp.Unknown, msg)
		ctx = callError(ctx, s.hooks, twerr)
	}
	callResponseSent(ctx, s.hooks)
}

func (s *connectorServer) serveConnectTwilioCall(ctx context.Context, resp http.ResponseWriter, req *http.Request) {
	header := req.Header.Get("Content-Type")
	i := strings.Index(header, ";")
	if i == -1 {
		i = len(header)
	}
	switch strings.TrimSpace(strings.ToLower(header[:i])) {
	case "application/json":
		s.serveConnectTwilioCallJSON(ctx, resp, req)
	case "application/protobuf":
		s.serveConnectTwilioCallProtobuf(ctx, resp, req)
	default:
		msg := fmt.Sprintf("unexpected Content-Type: %q", req.Header.Get("Content-Type"))
		twerr := badRouteError(msg, req.Method, req.URL.Path)
		s.writeError(ctx, resp, twerr)
	}
}

func (s *connectorServer) serveConnectTwilioCallJSON(ctx context.Context, resp http.ResponseWriter, req *http.Request) {
	var err error
	ctx = ctxsetters.WithMethodName(ctx, "ConnectTwilioCall")
	ctx, err = callRequestRouted(ctx, s.hooks)
	if err != nil {
		s.writeError(ctx, resp, err)
		return
	}

	d := json.NewDecoder(req.Body)
	rawReqBody := json.RawMessage{}
	if err := d.Decode(&rawReqBody); err != nil {
		s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err)
		return
	}
	reqContent := new(ConnectTwilioCallRequest)
	unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true}
	if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil {
		s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err)
		return
	}

	handler := s.Connector.ConnectTwilioCall
	if s.interceptor != nil {
		handler = func(ctx context.Context, req *ConnectTwilioCallRequest) (*ConnectTwilioCallResponse, error) {
			resp, err := s.interceptor(
				func(ctx context.Context, req interface{}) (interface{}, error) {
					typedReq, ok := req.(*ConnectTwilioCallRequest)
					if !ok {
						return nil, twirp.InternalError("failed type assertion req.(*ConnectTwilioCallRequest) when calling interceptor")
					}
					return s.Connector.ConnectTwilioCall(ctx, typedReq)
				},
			)(ctx, req)
			if resp != nil {
				typedResp, ok := resp.(*ConnectTwilioCallResponse)
				if !ok {
					return nil, twirp.InternalError("failed type assertion resp.(*ConnectTwilioCallResponse) when calling interceptor")
				}
				return typedResp, err
			}
			return nil, err
		}
	}

	// Call service method
	var respContent *ConnectTwilioCallResponse
	func() {
		defer ensurePanicResponses(ctx, resp, s.hooks)
		respContent, err = handler(ctx, reqContent)
	}()

	if err != nil {
		s.writeError(ctx, resp, err)
		return
	}
	if respContent == nil {
		s.writeError(ctx, resp, twirp.InternalError("received a nil *ConnectTwilioCallResponse and nil error while calling ConnectTwilioCall. nil responses are not supported"))
		return
	}

	ctx = callResponsePrepared(ctx, s.hooks)

	marshaler := &protojson.MarshalOptions{UseProtoNames: !s.jsonCamelCase, EmitUnpopulated: !s.jsonSkipDefaults}
	respBytes, err := marshaler.Marshal(respContent)
	if err != nil {
		s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response"))
		return
	}

	ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK)
	resp.Header().Set("Content-Type", "application/json")
	resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes)))
	resp.WriteHeader(http.StatusOK)

	if n, err := resp.Write(respBytes); err != nil {
		msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error())
		twerr := twirp.NewError(twirp.Unknown, msg)
		ctx = callError(ctx, s.hooks, twerr)
	}
	callResponseSent(ctx, s.hooks)
}

func (s *connectorServer) serveConnectTwilioCallProtobuf(ctx context.Context, resp http.ResponseWriter, req *http.Request) {
	var err error
	ctx = ctxsetters.WithMethodName(ctx, "ConnectTwilioCall")
	ctx, err = callRequestRouted(ctx, s.hooks)
	if err != nil {
		s.writeError(ctx, resp, err)
		return
	}

	buf, err := io.ReadAll(req.Body)
	if err != nil {
		s.handleRequestBodyError(ctx, resp, "failed to read request body", err)
		return
	}
	reqContent := new(ConnectTwilioCallRequest)
	if err = proto.Unmarshal(buf, reqContent); err != nil {
		s.writeError(ctx, resp, malformedRequestError("the protobuf request could not be decoded"))
		return
	}

	handler := s.Connector.ConnectTwilioCall
	if s.interceptor != nil {
		handler = func(ctx context.Context, req *ConnectTwilioCallRequest) (*ConnectTwilioCallResponse, error) {
			resp, err := s.interceptor(
				func(ctx context.Context, req interface{}) (interface{}, error) {
					typedReq, ok := req.(*ConnectTwilioCallRequest)
					if !ok {
						return nil, twirp.InternalError("failed type assertion req.(*ConnectTwilioCallRequest) when calling interceptor")
					}
					return s.Connector.ConnectTwilioCall(ctx, typedReq)
				},
			)(ctx, req)
			if resp != nil {
				typedResp, ok := resp.(*ConnectTwilioCallResponse)
				if !ok {
					return nil, twirp.InternalError("failed type assertion resp.(*ConnectTwilioCallResponse) when calling interceptor")
				}
				return typedResp, err
			}
			return nil, err
		}
	}

	// Call service method
	var respContent *ConnectTwilioCallResponse
	func() {
		defer ensurePanicResponses(ctx, resp, s.hooks)
		respContent, err = handler(ctx, reqContent)
	}()

	if err != nil {
		s.writeError(ctx, resp, err)
		return
	}
	if respContent == nil {
		s.writeError(ctx, resp, twirp.InternalError("received a nil *ConnectTwilioCallResponse and nil error while calling ConnectTwilioCall. nil responses are not supported"))
		return
	}

	ctx = callResponsePrepared(ctx, s.hooks)

	respBytes, err := proto.Marshal(respContent)
	if err != nil {
		s.writeError(ctx, resp, wrapInternal(err, "failed to marshal proto response"))
		return
	}

	ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK)
	resp.Header().Set("Content-Type", "application/protobuf")
	resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes)))
	resp.WriteHeader(http.StatusOK)
	if n, err := resp.Write(respBytes); err != nil {
		msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error())
		twerr := twirp.NewError(twirp.Unknown, msg)
		ctx = callError(ctx, s.hooks, twerr)
	}
	callResponseSent(ctx, s.hooks)
}

func (s *connectorServer) ServiceDescriptor() ([]byte, int) {
	return twirpFileDescriptor7, 0
}

func (s *connectorServer) ProtocGenTwirpVersion() string {
	return "v8.1.3"
}

// PathPrefix returns the base service path, in the form: "/<prefix>/<package>.<Service>/"
// that is everything in a Twirp route except for the <Method>. This can be used for routing,
// for example to identify the requests that are targeted to this service in a mux.
func (s *connectorServer) PathPrefix() string {
	return baseServicePath(s.pathPrefix, "livekit", "Connector")
}

var twirpFileDescriptor7 = []byte{
	// 313 bytes of a gzipped FileDescriptorProto
	0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x92, 0x41, 0x4b, 0xf3, 0x30,
	0x1c, 0xc6, 0xdf, 0xb7, 0xc2, 0xd4, 0xbf, 0x4e, 0x6b, 0x04, 0x85, 0x1e, 0x64, 0x5b, 0x45, 0xc1,
	0x43, 0x07, 0x7a, 0xeb, 0x6d, 0x76, 0x78, 0xd1, 0x83, 0xc8, 0x64, 0x30, 0x90, 0xd9, 0xc5, 0xe8,
	0xfe, 0x18, 0x9b, 0xb8, 0x64, 0x1b, 0x7e, 0x25, 0x3f, 0x9a, 0xf8, 0x21, 0x64, 0x6d, 0x52, 0xdd,
	0x3a, 0xeb, 0xb1, 0x79, 0x7e, 0xcf, 0xf3, 0x0b, 0x34, 0xb0, 0xcf, 0x71, 0xc2, 0x9e, 0x51, 0xf7,
	0xa9, 0x48, 0x12, 0x46, 0xb5, 0x18, 0x05, 0x72, 0x24, 0xb4, 0x20, 0xab, 0x26, 0xf0, 0x6a, 0x05,
	0xa2, 0x3f, 0x1d, 0xc6, 0x5a, 0xc5, 0x52, 0x66, 0xa8, 0x77, 0x50, 0x24, 0xf4, 0x14, 0x39, 0x8a,
	0x2c, 0x3f, 0x09, 0xa1, 0x1a, 0xd9, 0xa4, 0xf3, 0x26, 0x19, 0xd9, 0x86, 0x8d, 0xdb, 0x44, 0x49,
	0x46, 0xf1, 0x11, 0xd9, 0x83, 0xfb, 0x8f, 0x6c, 0xc2, 0x5a, 0x77, 0xb6, 0xd9, 0x92, 0xd2, 0xfd,
	0x4f, 0x00, 0x2a, 0x9d, 0xb4, 0xef, 0x3a, 0xa7, 0x9f, 0x2b, 0xb0, 0x9e, 0x97, 0x49, 0x17, 0xdc,
	0x36, 0xc6, 0xdc, 0xb2, 0x51, 0xcc, 0x39, 0xa9, 0x05, 0x46, 0x1f, 0x2c, 0x46, 0x37, 0xec, 0x75,
	0xcc, 0x94, 0xf6, 0xea, 0x25, 0x84, 0x92, 0x22, 0x51, 0x8c, 0x20, 0xec, 0xb5, 0x51, 0x99, 0xfb,
	0xcf, 0xcd, 0x1f, 0xfd, 0x28, 0x2f, 0x03, 0xac, 0xe4, 0xf8, 0x4f, 0xce, 0xa8, 0xee, 0x61, 0x37,
	0x5a, 0xe2, 0xf1, 0xf3, 0x7e, 0xf4, 0xbb, 0xe4, 0xb0, 0x1c, 0x32, 0x86, 0x3b, 0x20, 0x2d, 0x4a,
	0x99, 0x9c, 0x17, 0x34, 0xf2, 0x6e, 0x31, 0xb4, 0xfb, 0x7e, 0x29, 0x63, 0xe6, 0x7b, 0xb0, 0x63,
	0xec, 0xd9, 0x5f, 0x4a, 0xd7, 0xeb, 0x8b, 0x37, 0xfb, 0xce, 0xec, 0x78, 0xa3, 0x0c, 0xc9, 0xb6,
	0xcf, 0x2f, 0x7a, 0xfe, 0x13, 0xea, 0xe1, 0x78, 0x10, 0x50, 0xf1, 0xd2, 0x34, 0x7c, 0x33, 0x7d,
	0x46, 0x54, 0x70, 0x7b, 0xf0, 0xee, 0x54, 0xaf, 0x70, 0xc2, 0x2e, 0x51, 0x07, 0xd7, 0xb3, 0xe8,
	0xc3, 0xd9, 0x32, 0xdf, 0x61, 0x98, 0x1e, 0x0c, 0x2a, 0x69, 0xe5, 0xec, 0x2b, 0x00, 0x00, 0xff,
	0xff, 0xa0, 0x0c, 0x77, 0xd4, 0xdf, 0x02, 0x00, 0x00,
}
