// Code generated by protoc-gen-go_temporal. DO NOT EDIT.
// versions:
//
//	protoc-gen-go_temporal dev (latest)
//	protoc (unknown)
//
// source: example/nexus/v1/nexus.proto
package nexusv1temporal

import (
	"context"
	v1 "github.com/cludden/protoc-gen-go-temporal/gen/example/nexus/v1"
	nexusv1nexus "github.com/cludden/protoc-gen-go-temporal/gen/example/nexus/v1/nexusv1nexus"
	nexus "github.com/nexus-rpc/sdk-go/nexus"
	temporalnexus "go.temporal.io/sdk/temporalnexus"
	worker "go.temporal.io/sdk/worker"
)

// Nexus handler for example.nexus.v1.GreetingService
type GreetingServiceNexusHandler struct{}

// generates a friendly greeting based on the input name and language
func (h *GreetingServiceNexusHandler) Hello(name string) nexus.Operation[*v1.HelloInput, *v1.HelloOutput] {
	return temporalnexus.MustNewWorkflowRunOperationWithOptions(temporalnexus.WorkflowRunOperationOptions[*v1.HelloInput, *v1.HelloOutput]{
		Handler: func(ctx context.Context, input *v1.HelloInput, opts nexus.StartOperationOptions) (temporalnexus.WorkflowHandle[*v1.HelloOutput], error) {
			o, err := v1.NewHelloOptions().Build(input.ProtoReflect())
			if err != nil {
				return nil, err
			}
			return temporalnexus.ExecuteUntypedWorkflow[*v1.HelloOutput](ctx, opts, o, v1.HelloWorkflowName, input)
		},
		Name: name,
	})
}

// RegisterGreetingServiceNexusService initializes a new GreetingService nexus service and registers it with the provided registry
func RegisterGreetingServiceNexusService(r worker.NexusServiceRegistry) error {
	svc, err := nexusv1nexus.NewGreetingServiceNexusService(&GreetingServiceNexusHandler{})
	if err != nil {
		return err
	}
	r.RegisterNexusService(svc)
	return nil
}
