// Code generated by protoc-gen-grpc-api-gateway. DO NOT EDIT.
// source: signer/v1/service.proto

/*
Package signerv1 is a reverse proxy.

It translates gRPC into RESTful JSON APIs.
*/
package signerv1

import (
	"context"
	"io"
	"net/http"

	"github.com/meshapi/grpc-api-gateway/gateway"
	"google.golang.org/grpc"
	"google.golang.org/grpc/grpclog"
	"google.golang.org/protobuf/proto"
)

func request_SignerService_GetStatus_0(ctx context.Context, marshaler gateway.Marshaler, mux *gateway.ServeMux, client SignerServiceClient, req *http.Request, pathParams gateway.Params) (proto.Message, gateway.ServerMetadata, error) {
	var protoReq GetStatusRequest
	var metadata gateway.ServerMetadata

	msg, err := client.GetStatus(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
	return msg, metadata, err

}

func request_SignerService_GetPubkey_0(ctx context.Context, marshaler gateway.Marshaler, mux *gateway.ServeMux, client SignerServiceClient, req *http.Request, pathParams gateway.Params) (proto.Message, gateway.ServerMetadata, error) {
	var protoReq GetPubkeyRequest
	var metadata gateway.ServerMetadata

	msg, err := client.GetPubkey(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
	return msg, metadata, err

}

func request_SignerService_SignTransaction_0(ctx context.Context, marshaler gateway.Marshaler, mux *gateway.ServeMux, client SignerServiceClient, req *http.Request, pathParams gateway.Params) (proto.Message, gateway.ServerMetadata, error) {
	var protoReq SignTransactionRequest
	var metadata gateway.ServerMetadata

	if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF {
		return nil, metadata, gateway.ErrMarshal{Err: err, Inbound: true}
	}

	msg, err := client.SignTransaction(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
	return msg, metadata, err

}

func request_SignerService_SignTransactionTapscript_0(ctx context.Context, marshaler gateway.Marshaler, mux *gateway.ServeMux, client SignerServiceClient, req *http.Request, pathParams gateway.Params) (proto.Message, gateway.ServerMetadata, error) {
	var protoReq SignTransactionTapscriptRequest
	var metadata gateway.ServerMetadata

	if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF {
		return nil, metadata, gateway.ErrMarshal{Err: err, Inbound: true}
	}

	msg, err := client.SignTransactionTapscript(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
	return msg, metadata, err

}

// RegisterSignerServiceHandlerFromEndpoint is same as RegisterSignerServiceHandler but
// automatically dials to "endpoint" and closes the connection when "ctx" gets done.
func RegisterSignerServiceHandlerFromEndpoint(ctx context.Context, mux *gateway.ServeMux, endpoint string, opts []grpc.DialOption) error {
	conn, err := grpc.DialContext(ctx, endpoint, opts...)
	if err != nil {
		return err
	}
	defer func() {
		if err != nil {
			if cerr := conn.Close(); cerr != nil {
				grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr)
			}
			return
		}
		go func() {
			<-ctx.Done()
			if cerr := conn.Close(); cerr != nil {
				grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr)
			}
		}()
	}()

	RegisterSignerServiceHandler(ctx, mux, conn)
	return nil
}

// RegisterSignerServiceHandler registers the http handlers for service SignerService to "mux".
// The handlers forward requests to the grpc endpoint over "conn".
func RegisterSignerServiceHandler(ctx context.Context, mux *gateway.ServeMux, conn *grpc.ClientConn) {
	RegisterSignerServiceHandlerClient(ctx, mux, NewSignerServiceClient(conn))
}

// RegisterSignerServiceHandlerClient registers the http handlers for service SignerService
// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "SignerServiceClient".
// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "SignerServiceClient"
// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in
// "SignerServiceClient" to call the correct interceptors.
func RegisterSignerServiceHandlerClient(ctx context.Context, mux *gateway.ServeMux, client SignerServiceClient) {

	mux.HandleWithParams("GET", "/v1/status", func(w http.ResponseWriter, req *http.Request, pathParams gateway.Params) {
		ctx, cancel := context.WithCancel(req.Context())
		defer cancel()
		inboundMarshaler, outboundMarshaler := mux.MarshalerForRequest(req)
		var err error
		var annotatedContext context.Context
		annotatedContext, err = gateway.AnnotateContext(ctx, mux, req, "/signer.v1.SignerService/GetStatus", gateway.WithHTTPPathPattern("/v1/status"))
		if err != nil {
			mux.HTTPError(ctx, outboundMarshaler, w, req, err)
			return
		}

		resp, md, err := request_SignerService_GetStatus_0(annotatedContext, inboundMarshaler, mux, client, req, pathParams)
		annotatedContext = gateway.NewServerMetadataContext(annotatedContext, md)
		if err != nil {
			mux.HTTPError(annotatedContext, outboundMarshaler, w, req, err)
			return
		}

		mux.ForwardResponseMessage(annotatedContext, outboundMarshaler, w, req, resp)
	})

	mux.HandleWithParams("GET", "/v1/pubkey", func(w http.ResponseWriter, req *http.Request, pathParams gateway.Params) {
		ctx, cancel := context.WithCancel(req.Context())
		defer cancel()
		inboundMarshaler, outboundMarshaler := mux.MarshalerForRequest(req)
		var err error
		var annotatedContext context.Context
		annotatedContext, err = gateway.AnnotateContext(ctx, mux, req, "/signer.v1.SignerService/GetPubkey", gateway.WithHTTPPathPattern("/v1/pubkey"))
		if err != nil {
			mux.HTTPError(ctx, outboundMarshaler, w, req, err)
			return
		}

		resp, md, err := request_SignerService_GetPubkey_0(annotatedContext, inboundMarshaler, mux, client, req, pathParams)
		annotatedContext = gateway.NewServerMetadataContext(annotatedContext, md)
		if err != nil {
			mux.HTTPError(annotatedContext, outboundMarshaler, w, req, err)
			return
		}

		mux.ForwardResponseMessage(annotatedContext, outboundMarshaler, w, req, resp)
	})

	mux.HandleWithParams("POST", "/v1/sign-transaction", func(w http.ResponseWriter, req *http.Request, pathParams gateway.Params) {
		ctx, cancel := context.WithCancel(req.Context())
		defer cancel()
		inboundMarshaler, outboundMarshaler := mux.MarshalerForRequest(req)
		var err error
		var annotatedContext context.Context
		annotatedContext, err = gateway.AnnotateContext(ctx, mux, req, "/signer.v1.SignerService/SignTransaction", gateway.WithHTTPPathPattern("/v1/sign-transaction"))
		if err != nil {
			mux.HTTPError(ctx, outboundMarshaler, w, req, err)
			return
		}

		resp, md, err := request_SignerService_SignTransaction_0(annotatedContext, inboundMarshaler, mux, client, req, pathParams)
		annotatedContext = gateway.NewServerMetadataContext(annotatedContext, md)
		if err != nil {
			mux.HTTPError(annotatedContext, outboundMarshaler, w, req, err)
			return
		}

		mux.ForwardResponseMessage(annotatedContext, outboundMarshaler, w, req, resp)
	})

	mux.HandleWithParams("POST", "/v1/sign-transaction-tapscript", func(w http.ResponseWriter, req *http.Request, pathParams gateway.Params) {
		ctx, cancel := context.WithCancel(req.Context())
		defer cancel()
		inboundMarshaler, outboundMarshaler := mux.MarshalerForRequest(req)
		var err error
		var annotatedContext context.Context
		annotatedContext, err = gateway.AnnotateContext(ctx, mux, req, "/signer.v1.SignerService/SignTransactionTapscript", gateway.WithHTTPPathPattern("/v1/sign-transaction-tapscript"))
		if err != nil {
			mux.HTTPError(ctx, outboundMarshaler, w, req, err)
			return
		}

		resp, md, err := request_SignerService_SignTransactionTapscript_0(annotatedContext, inboundMarshaler, mux, client, req, pathParams)
		annotatedContext = gateway.NewServerMetadataContext(annotatedContext, md)
		if err != nil {
			mux.HTTPError(annotatedContext, outboundMarshaler, w, req, err)
			return
		}

		mux.ForwardResponseMessage(annotatedContext, outboundMarshaler, w, req, resp)
	})

}
