// Code generated by protoc-gen-go_temporal. DO NOT EDIT.
// versions:
//
//	protoc-gen-go_temporal dev (latest)
//	protoc (unknown)
//
// source: test/option/v1/option.proto
package optionv1

import (
	"context"
	"errors"
	"fmt"
	expression "github.com/cludden/protoc-gen-go-temporal/pkg/expression"
	helpers "github.com/cludden/protoc-gen-go-temporal/pkg/helpers"
	scheme "github.com/cludden/protoc-gen-go-temporal/pkg/scheme"
	testutil "github.com/cludden/protoc-gen-go-temporal/pkg/testutil"
	uuid "github.com/google/uuid"
	gohomedir "github.com/mitchellh/go-homedir"
	v2 "github.com/urfave/cli/v2"
	enumsv1 "go.temporal.io/api/enums/v1"
	serviceerror "go.temporal.io/api/serviceerror"
	activity "go.temporal.io/sdk/activity"
	client "go.temporal.io/sdk/client"
	converter "go.temporal.io/sdk/converter"
	temporal "go.temporal.io/sdk/temporal"
	testsuite "go.temporal.io/sdk/testsuite"
	worker "go.temporal.io/sdk/worker"
	workflow "go.temporal.io/sdk/workflow"
	protojson "google.golang.org/protobuf/encoding/protojson"
	protoreflect "google.golang.org/protobuf/reflect/protoreflect"
	"log/slog"
	"os"
	"sort"
	"strings"
	"sync"
	"sync/atomic"
	"time"
)

// TestTaskQueue is the default task-queue for a test.option.v1.Test worker
var TestTaskQueue = "option-v1"

// test.option.v1.Test workflow names
const (
	WorkflowWithInputWorkflowName = "test.option.v1.Test.WorkflowWithInput"
)

// test.option.v1.Test workflow id expressions
var (
	WorkflowWithInputIdexpression = expression.MustParseExpression("workflow-with-input:${! name.or(throw(\"name is required\")) }")
)

// test.option.v1.Test workflow search attribute mappings
var (
	WorkflowWithInputSearchAttributesMapping = expression.MustParseMapping("name = name \n")
)

// test.option.v1.Test activity names
const (
	ActivityWithInputActivityName = "test.option.v1.Test.ActivityWithInput"
)

// test.option.v1.Test update names
const (
	UpdateWithInputUpdateName = "test.option.v1.Test.UpdateWithInput"
)

// test.option.v1.Test update id expressions
var (
	UpdateWithInputIdexpression = expression.MustParseExpression("update-with-input:${! name.or(throw(\"name is required\")) }")
)

// TestClient describes a client for a(n) test.option.v1.Test worker
type TestClient interface {
	// WorkflowWithInput executes a(n) test.option.v1.Test.WorkflowWithInput workflow and blocks until error or response received
	WorkflowWithInput(ctx context.Context, req *WorkflowWithInputRequest, opts ...*WorkflowWithInputOptions) error

	// WorkflowWithInputAsync starts a(n) test.option.v1.Test.WorkflowWithInput workflow and returns a handle to the workflow run
	WorkflowWithInputAsync(ctx context.Context, req *WorkflowWithInputRequest, opts ...*WorkflowWithInputOptions) (WorkflowWithInputRun, error)

	// GetWorkflowWithInput retrieves a handle to an existing test.option.v1.Test.WorkflowWithInput workflow execution
	GetWorkflowWithInput(ctx context.Context, workflowID string, runID string) WorkflowWithInputRun

	// CancelWorkflow requests cancellation of an existing workflow execution
	CancelWorkflow(ctx context.Context, workflowID string, runID string) error

	// TerminateWorkflow an existing workflow execution
	TerminateWorkflow(ctx context.Context, workflowID string, runID string, reason string, details ...interface{}) error

	// UpdateWithInput executes a(n) test.option.v1.Test.UpdateWithInput update and blocks until update completion
	UpdateWithInput(ctx context.Context, workflowID string, runID string, req *UpdateWithInputRequest, opts ...*UpdateWithInputOptions) error

	// UpdateWithInputAsync starts a(n) test.option.v1.Test.UpdateWithInput update and returns a handle to the workflow update
	UpdateWithInputAsync(ctx context.Context, workflowID string, runID string, req *UpdateWithInputRequest, opts ...*UpdateWithInputOptions) (UpdateWithInputHandle, error)

	// GetUpdateWithInput retrieves a handle to an existing test.option.v1.Test.UpdateWithInput update
	GetUpdateWithInput(ctx context.Context, req client.GetWorkflowUpdateHandleOptions) (UpdateWithInputHandle, error)
}

// testClient implements a temporal client for a test.option.v1.Test service
type testClient struct {
	client client.Client
	log    *slog.Logger
}

// NewTestClient initializes a new test.option.v1.Test client
func NewTestClient(c client.Client, options ...*testClientOptions) TestClient {
	var cfg *testClientOptions
	if len(options) > 0 {
		cfg = options[0]
	} else {
		cfg = NewTestClientOptions()
	}
	return &testClient{
		client: c,
		log:    cfg.getLogger(),
	}
}

// NewTestClientWithOptions initializes a new Test client with the given options
func NewTestClientWithOptions(c client.Client, opts client.Options, options ...*testClientOptions) (TestClient, error) {
	var err error
	c, err = client.NewClientFromExisting(c, opts)
	if err != nil {
		return nil, fmt.Errorf("error initializing client with options: %w", err)
	}
	var cfg *testClientOptions
	if len(options) > 0 {
		cfg = options[0]
	} else {
		cfg = NewTestClientOptions()
	}
	return &testClient{
		client: c,
		log:    cfg.getLogger(),
	}, nil
}

// testClientOptions describes optional runtime configuration for a TestClient
type testClientOptions struct {
	log *slog.Logger
}

// NewTestClientOptions initializes a new testClientOptions value
func NewTestClientOptions() *testClientOptions {
	return &testClientOptions{}
}

// WithLogger can be used to override the default logger
func (opts *testClientOptions) WithLogger(l *slog.Logger) *testClientOptions {
	if l != nil {
		opts.log = l
	}
	return opts
}

// getLogger returns the configured logger, or the default logger
func (opts *testClientOptions) getLogger() *slog.Logger {
	if opts != nil && opts.log != nil {
		return opts.log
	}
	return slog.Default()
}

// test.option.v1.Test.WorkflowWithInput executes a test.option.v1.Test.WorkflowWithInput workflow and blocks until error or response received
func (c *testClient) WorkflowWithInput(ctx context.Context, req *WorkflowWithInputRequest, options ...*WorkflowWithInputOptions) error {
	run, err := c.WorkflowWithInputAsync(ctx, req, options...)
	if err != nil {
		return err
	}
	return run.Get(ctx)
}

// WorkflowWithInputAsync starts a(n) test.option.v1.Test.WorkflowWithInput workflow and returns a handle to the workflow run
func (c *testClient) WorkflowWithInputAsync(ctx context.Context, req *WorkflowWithInputRequest, options ...*WorkflowWithInputOptions) (WorkflowWithInputRun, error) {
	var o *WorkflowWithInputOptions
	if len(options) > 0 && options[0] != nil {
		o = options[0]
	} else {
		o = NewWorkflowWithInputOptions()
	}
	opts, err := o.Build(req.ProtoReflect())
	if err != nil {
		return nil, fmt.Errorf("error initializing client.StartWorkflowOptions: %w", err)
	}
	run, err := c.client.ExecuteWorkflow(ctx, opts, WorkflowWithInputWorkflowName, req)
	if err != nil {
		return nil, err
	}
	if run == nil {
		return nil, errors.New("execute workflow returned nil run")
	}
	return &workflowWithInputRun{
		client: c,
		run:    run,
	}, nil
}

// GetWorkflowWithInput fetches an existing test.option.v1.Test.WorkflowWithInput execution
func (c *testClient) GetWorkflowWithInput(ctx context.Context, workflowID string, runID string) WorkflowWithInputRun {
	return &workflowWithInputRun{
		client: c,
		run:    c.client.GetWorkflow(ctx, workflowID, runID),
	}
}

// CancelWorkflow requests cancellation of an existing workflow execution
func (c *testClient) CancelWorkflow(ctx context.Context, workflowID string, runID string) error {
	return c.client.CancelWorkflow(ctx, workflowID, runID)
}

// TerminateWorkflow terminates an existing workflow execution
func (c *testClient) TerminateWorkflow(ctx context.Context, workflowID string, runID string, reason string, details ...interface{}) error {
	return c.client.TerminateWorkflow(ctx, workflowID, runID, reason, details...)
}

// test.option.v1.Test.UpdateWithInput sends a(n) test.option.v1.Test.UpdateWithInput update to an existing workflow
func (c *testClient) UpdateWithInput(ctx context.Context, workflowID string, runID string, req *UpdateWithInputRequest, opts ...*UpdateWithInputOptions) error {
	// initialize update options
	o := NewUpdateWithInputOptions()
	if len(opts) > 0 && opts[0].Options != nil {
		o = opts[0]
	}

	// call sync update with WorkflowUpdateStageCompleted wait policy
	handle, err := c.UpdateWithInputAsync(ctx, workflowID, runID, req, o.WithWaitPolicy(client.WorkflowUpdateStageCompleted))
	if err != nil {
		return err
	}

	// block on update completion
	return handle.Get(ctx)
}

// test.option.v1.Test.UpdateWithInput sends a(n) test.option.v1.Test.UpdateWithInput update to an existing workflow
func (c *testClient) UpdateWithInputAsync(ctx context.Context, workflowID string, runID string, req *UpdateWithInputRequest, opts ...*UpdateWithInputOptions) (UpdateWithInputHandle, error) {
	// initialize update options
	var o *UpdateWithInputOptions
	if len(opts) > 0 && opts[0] != nil {
		o = opts[0]
	} else {
		o = NewUpdateWithInputOptions()
	}

	// build UpdateWorkflowOptions
	options, err := o.Build(workflowID, runID, req)
	if err != nil {
		return nil, fmt.Errorf("error initializing UpdateWorkflowWithOptions: %w", err)
	}

	// update workflow
	handle, err := c.client.UpdateWorkflow(ctx, *options)
	if err != nil {
		return nil, err
	}
	return &updateWithInputHandle{client: c, handle: handle}, nil
}

// GetUpdateWithInput retrieves a handle to an existing test.option.v1.Test.UpdateWithInput update
func (c *testClient) GetUpdateWithInput(ctx context.Context, req client.GetWorkflowUpdateHandleOptions) (UpdateWithInputHandle, error) {
	return &updateWithInputHandle{
		client: c,
		handle: c.client.GetWorkflowUpdateHandle(req),
	}, nil
}

// WorkflowWithInputOptions provides configuration for a test.option.v1.Test.WorkflowWithInput workflow operation
type WorkflowWithInputOptions struct {
	options                  client.StartWorkflowOptions
	executionTimeout         *time.Duration
	id                       *string
	idReusePolicy            enumsv1.WorkflowIdReusePolicy
	retryPolicy              *temporal.RetryPolicy
	runTimeout               *time.Duration
	searchAttributes         map[string]any
	taskQueue                *string
	taskTimeout              *time.Duration
	workflowIdConflictPolicy enumsv1.WorkflowIdConflictPolicy
}

// NewWorkflowWithInputOptions initializes a new WorkflowWithInputOptions value
func NewWorkflowWithInputOptions() *WorkflowWithInputOptions {
	return &WorkflowWithInputOptions{}
}

// Build initializes a new go.temporal.io/sdk/client.StartWorkflowOptions value with defaults and overrides applied
func (o *WorkflowWithInputOptions) Build(req protoreflect.Message) (client.StartWorkflowOptions, error) {
	opts := o.options
	if v := o.id; v != nil {
		opts.ID = *v
	} else if opts.ID == "" {
		id, err := expression.EvalExpression(WorkflowWithInputIdexpression, req)
		if err != nil {
			return opts, fmt.Errorf("error evaluating id expression for %q workflow: %w", WorkflowWithInputWorkflowName, err)
		}
		opts.ID = id
	}
	if v := o.idReusePolicy; v != enumsv1.WORKFLOW_ID_REUSE_POLICY_UNSPECIFIED {
		opts.WorkflowIDReusePolicy = v
	} else if opts.WorkflowIDReusePolicy == enumsv1.WORKFLOW_ID_REUSE_POLICY_UNSPECIFIED {
		opts.WorkflowIDReusePolicy = enumsv1.WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE_FAILED_ONLY
	}
	if v := o.workflowIdConflictPolicy; v != enumsv1.WORKFLOW_ID_CONFLICT_POLICY_UNSPECIFIED {
		opts.WorkflowIDConflictPolicy = v
	} else if opts.WorkflowIDConflictPolicy == enumsv1.WORKFLOW_ID_CONFLICT_POLICY_UNSPECIFIED {
		opts.WorkflowIDConflictPolicy = enumsv1.WORKFLOW_ID_CONFLICT_POLICY_USE_EXISTING
	}
	if v := o.taskQueue; v != nil {
		opts.TaskQueue = *v
	} else if opts.TaskQueue == "" {
		opts.TaskQueue = "option-v2"
	}
	if v := o.retryPolicy; v != nil {
		opts.RetryPolicy = v
	} else if opts.RetryPolicy == nil {
		opts.RetryPolicy = &temporal.RetryPolicy{
			MaximumAttempts: int32(5),
		}
	}
	if v := o.searchAttributes; v != nil {
		opts.SearchAttributes = o.searchAttributes
	} else if opts.SearchAttributes == nil {
		structured, err := expression.ToStructured(req)
		if err != nil {
			return opts, fmt.Errorf("error serializing input for \"WorkflowWithInput\" search attribute mapping: %v", err)
		}
		result, err := WorkflowWithInputSearchAttributesMapping.Query(structured)
		if err != nil {
			return opts, fmt.Errorf("error executing \"WorkflowWithInput\" search attribute mapping: %v", err)
		}
		searchAttributes, ok := result.(map[string]any)
		if !ok {
			return opts, fmt.Errorf("expected \"WorkflowWithInput\" search attribute mapping to return map[string]any, got: %T", result)
		}
		opts.SearchAttributes = searchAttributes
	}
	if v := o.executionTimeout; v != nil {
		opts.WorkflowExecutionTimeout = *v
	} else if opts.WorkflowExecutionTimeout == 0 {
		opts.WorkflowExecutionTimeout = 600000000000 // 10 minutes
	}
	if v := o.runTimeout; v != nil {
		opts.WorkflowRunTimeout = *v
	} else if opts.WorkflowRunTimeout == 0 {
		opts.WorkflowRunTimeout = 300000000000 // 5 minutes
	}
	if v := o.taskTimeout; v != nil {
		opts.WorkflowTaskTimeout = *v
	} else if opts.WorkflowTaskTimeout == 0 {
		opts.WorkflowTaskTimeout = 10000000000 // 10 seconds
	}
	return opts, nil
}

// WithStartWorkflowOptions sets the initial go.temporal.io/sdk/client.StartWorkflowOptions
func (o *WorkflowWithInputOptions) WithStartWorkflowOptions(options client.StartWorkflowOptions) *WorkflowWithInputOptions {
	o.options = options
	return o
}

// WithExecutionTimeout sets the WorkflowExecutionTimeout value
func (o *WorkflowWithInputOptions) WithExecutionTimeout(d time.Duration) *WorkflowWithInputOptions {
	o.executionTimeout = &d
	return o
}

// WithID sets the ID value
func (o *WorkflowWithInputOptions) WithID(id string) *WorkflowWithInputOptions {
	o.id = &id
	return o
}

// WithIDReusePolicy sets the WorkflowIDReusePolicy value
func (o *WorkflowWithInputOptions) WithIDReusePolicy(policy enumsv1.WorkflowIdReusePolicy) *WorkflowWithInputOptions {
	o.idReusePolicy = policy
	return o
}

// WithRetryPolicy sets the RetryPolicy value
func (o *WorkflowWithInputOptions) WithRetryPolicy(policy *temporal.RetryPolicy) *WorkflowWithInputOptions {
	o.retryPolicy = policy
	return o
}

// WithRunTimeout sets the WorkflowRunTimeout value
func (o *WorkflowWithInputOptions) WithRunTimeout(d time.Duration) *WorkflowWithInputOptions {
	o.runTimeout = &d
	return o
}

// WithSearchAttributes sets the SearchAttributes value
func (o *WorkflowWithInputOptions) WithSearchAttributes(sa map[string]any) *WorkflowWithInputOptions {
	o.searchAttributes = sa
	return o
}

// WithTaskTimeout sets the WorkflowTaskTimeout value
func (o *WorkflowWithInputOptions) WithTaskTimeout(d time.Duration) *WorkflowWithInputOptions {
	o.taskTimeout = &d
	return o
}

// WithTaskQueue sets the TaskQueue value
func (o *WorkflowWithInputOptions) WithTaskQueue(tq string) *WorkflowWithInputOptions {
	o.taskQueue = &tq
	return o
}

// WithWorkflowIdConflictPolicy sets the WorkflowIdConflictPolicy value
func (o *WorkflowWithInputOptions) WithWorkflowIdConflictPolicy(policy enumsv1.WorkflowIdConflictPolicy) *WorkflowWithInputOptions {
	o.workflowIdConflictPolicy = policy
	return o
}

// WorkflowWithInputRun describes a(n) test.option.v1.Test.WorkflowWithInput workflow run
type WorkflowWithInputRun interface {
	// ID returns the workflow ID
	ID() string

	// RunID returns the workflow instance ID
	RunID() string

	// Run returns the inner client.WorkflowRun
	Run() client.WorkflowRun

	// Get blocks until the workflow is complete and returns the result
	Get(ctx context.Context) error

	// Cancel requests cancellation of a workflow in execution, returning an error if applicable
	Cancel(ctx context.Context) error

	// Terminate terminates a workflow in execution, returning an error if applicable
	Terminate(ctx context.Context, reason string, details ...interface{}) error

	// test.option.v1.Test.UpdateWithInput executes a(n) test.option.v1.Test.UpdateWithInput update
	UpdateWithInput(ctx context.Context, req *UpdateWithInputRequest, opts ...*UpdateWithInputOptions) error

	// test.option.v1.Test.UpdateWithInputAsync sends a(n) test.option.v1.Test.UpdateWithInput update to the workflow
	UpdateWithInputAsync(ctx context.Context, req *UpdateWithInputRequest, opts ...*UpdateWithInputOptions) (UpdateWithInputHandle, error)
}

// workflowWithInputRun provides an internal implementation of a(n) WorkflowWithInputRunRun
type workflowWithInputRun struct {
	client *testClient
	run    client.WorkflowRun
}

// ID returns the workflow ID
func (r *workflowWithInputRun) ID() string {
	return r.run.GetID()
}

// Run returns the inner client.WorkflowRun
func (r *workflowWithInputRun) Run() client.WorkflowRun {
	return r.run
}

// RunID returns the execution ID
func (r *workflowWithInputRun) RunID() string {
	return r.run.GetRunID()
}

// Cancel requests cancellation of a workflow in execution, returning an error if applicable
func (r *workflowWithInputRun) Cancel(ctx context.Context) error {
	return r.client.CancelWorkflow(ctx, r.ID(), r.RunID())
}

// Get blocks until the workflow is complete, returning the result if applicable
func (r *workflowWithInputRun) Get(ctx context.Context) error {
	return r.run.Get(ctx, nil)
}

// Terminate terminates a workflow in execution, returning an error if applicable
func (r *workflowWithInputRun) Terminate(ctx context.Context, reason string, details ...interface{}) error {
	return r.client.TerminateWorkflow(ctx, r.ID(), r.RunID(), reason, details...)
}

// test.option.v1.Test.UpdateWithInput executes a(n) test.option.v1.Test.UpdateWithInput workflow update
func (r *workflowWithInputRun) UpdateWithInput(ctx context.Context, req *UpdateWithInputRequest, opts ...*UpdateWithInputOptions) error {
	return r.client.UpdateWithInput(ctx, r.ID(), r.RunID(), req, opts...)
}

// UpdateWithInputAsync start a(n) test.option.v1.Test.UpdateWithInput workflow update and returns a handle to the update
func (r *workflowWithInputRun) UpdateWithInputAsync(ctx context.Context, req *UpdateWithInputRequest, opts ...*UpdateWithInputOptions) (UpdateWithInputHandle, error) {
	return r.client.UpdateWithInputAsync(ctx, r.ID(), r.RunID(), req, opts...)
}

// UpdateWithInputHandle describes a(n) test.option.v1.Test.UpdateWithInput update handle
type UpdateWithInputHandle interface {
	// WorkflowID returns the workflow ID
	WorkflowID() string
	// RunID returns the workflow instance ID
	RunID() string
	// UpdateID returns the update ID
	UpdateID() string
	// Get blocks until the workflow is complete and returns the result
	Get(ctx context.Context) error
}

// updateWithInputHandle provides an internal implementation of a(n) UpdateWithInputHandle
type updateWithInputHandle struct {
	client *testClient
	handle client.WorkflowUpdateHandle
}

// WorkflowID returns the workflow ID
func (h *updateWithInputHandle) WorkflowID() string {
	return h.handle.WorkflowID()
}

// RunID returns the execution ID
func (h *updateWithInputHandle) RunID() string {
	return h.handle.RunID()
}

// UpdateID returns the update ID
func (h *updateWithInputHandle) UpdateID() string {
	return h.handle.UpdateID()
}

// Get blocks until the update wait policy is met, returning the result if applicable
func (h *updateWithInputHandle) Get(ctx context.Context) error {
	var err error
	doneCh := make(chan struct{})
	gctx, cancel := context.WithCancel(context.Background())
	defer cancel()

	go func() {
		for {
			var deadlineExceeded *serviceerror.DeadlineExceeded
			if err = h.handle.Get(gctx, nil); err != nil && ctx.Err() == nil && (errors.As(err, &deadlineExceeded) || strings.Contains(err.Error(), context.DeadlineExceeded.Error())) {
				continue
			}
			break
		}
		close(doneCh)
	}()

	select {
	case <-ctx.Done():
		return ctx.Err()
	case <-doneCh:
		return err
	}
}

// UpdateWithInputOptions provides configuration for a test.option.v1.Test.UpdateWithInput update operation
type UpdateWithInputOptions struct {
	Options    *client.UpdateWorkflowOptions
	id         *string
	waitPolicy client.WorkflowUpdateStage
}

// NewUpdateWithInputOptions initializes a new UpdateWithInputOptions value
func NewUpdateWithInputOptions() *UpdateWithInputOptions {
	return &UpdateWithInputOptions{Options: &client.UpdateWorkflowOptions{}}
}

// Build initializes a new client.UpdateWorkflowOptions with defaults and overrides applied
func (o *UpdateWithInputOptions) Build(workflowID string, runID string, req *UpdateWithInputRequest) (opts *client.UpdateWorkflowOptions, err error) {
	// use user-provided UpdateWorkflowOptions if exists
	if o.Options != nil {
		opts = o.Options
	} else {
		opts = &client.UpdateWorkflowOptions{}
	}

	// set constants
	opts.Args = []any{req}
	opts.RunID = runID
	opts.UpdateName = UpdateWithInputUpdateName
	opts.WorkflowID = workflowID

	// set UpdateID
	if v := o.id; v != nil {
		opts.UpdateID = *v
	} else if opts.UpdateID == "" {
		id, err := expression.EvalExpression(UpdateWithInputIdexpression, req.ProtoReflect())
		if err != nil {
			return nil, fmt.Errorf("error evaluating id expression for %q update: %w", UpdateWithInputUpdateName, err)
		}
		opts.UpdateID = id
	}

	// set WaitPolicy
	if v := o.waitPolicy; v != client.WorkflowUpdateStageUnspecified {
		opts.WaitForStage = v
	} else if opts.WaitForStage == client.WorkflowUpdateStageUnspecified {
		opts.WaitForStage = client.WorkflowUpdateStageCompleted
	}
	return opts, nil
}

// WithUpdateID sets the UpdateID
func (o *UpdateWithInputOptions) WithUpdateID(id string) *UpdateWithInputOptions {
	o.id = &id
	return o
}

// WithUpdateWorkflowOptions sets the initial client.UpdateWorkflowOptions
func (o *UpdateWithInputOptions) WithUpdateWorkflowOptions(options client.UpdateWorkflowOptions) *UpdateWithInputOptions {
	o.Options = &options
	return o
}

// WithWaitPolicy sets the WaitPolicy
func (o *UpdateWithInputOptions) WithWaitPolicy(policy client.WorkflowUpdateStage) *UpdateWithInputOptions {
	o.waitPolicy = policy
	return o
}

// Reference to generated workflow functions
var (
	// testRegistrationMutex is a mutex for registering test.option.v1.Test workflows
	testRegistrationMutex sync.Mutex
	// WorkflowWithInputFunction implements a "test.option.v1.Test.WorkflowWithInput" workflow
	WorkflowWithInputFunction func(workflow.Context, *WorkflowWithInputRequest) error
)

// TestWorkflowFunctions describes a mockable dependency for inlining workflows within other workflows
type (
	// TestWorkflowFunctions describes a mockable dependency for inlining workflows within other workflows
	TestWorkflowFunctions interface {
		// WorkflowWithInput executes a "test.option.v1.Test.WorkflowWithInput" workflow inline
		WorkflowWithInput(workflow.Context, *WorkflowWithInputRequest) error
	}
	// testWorkflowFunctions provides an internal TestWorkflowFunctions implementation
	testWorkflowFunctions struct{}
)

func NewTestWorkflowFunctions() TestWorkflowFunctions {
	return &testWorkflowFunctions{}
}

// WorkflowWithInput executes a "test.option.v1.Test.WorkflowWithInput" workflow inline
func (f *testWorkflowFunctions) WorkflowWithInput(ctx workflow.Context, req *WorkflowWithInputRequest) error {
	if WorkflowWithInputFunction == nil {
		return errors.New("WorkflowWithInput requires workflow registration via RegisterTestWorkflows or RegisterWorkflowWithInputWorkflow")
	}
	return WorkflowWithInputFunction(ctx, req)
}

// TestWorkflows provides methods for initializing new test.option.v1.Test workflow values
type TestWorkflows interface {
	// WorkflowWithInput initializes a new a(n) WorkflowWithInputWorkflow implementation
	WorkflowWithInput(ctx workflow.Context, input *WorkflowWithInputWorkflowInput) (WorkflowWithInputWorkflow, error)
}

// RegisterTestWorkflows registers test.option.v1.Test workflows with the given worker
func RegisterTestWorkflows(r worker.WorkflowRegistry, workflows TestWorkflows) {
	RegisterWorkflowWithInputWorkflow(r, workflows.WorkflowWithInput)
}

// RegisterWorkflowWithInputWorkflow registers a test.option.v1.Test.WorkflowWithInput workflow with the given worker
func RegisterWorkflowWithInputWorkflow(r worker.WorkflowRegistry, wf func(workflow.Context, *WorkflowWithInputWorkflowInput) (WorkflowWithInputWorkflow, error)) {
	testRegistrationMutex.Lock()
	defer testRegistrationMutex.Unlock()
	WorkflowWithInputFunction = buildWorkflowWithInput(wf)
	r.RegisterWorkflowWithOptions(WorkflowWithInputFunction, workflow.RegisterOptions{Name: WorkflowWithInputWorkflowName})
}

// buildWorkflowWithInput converts a WorkflowWithInput workflow struct into a valid workflow function
func buildWorkflowWithInput(ctor func(workflow.Context, *WorkflowWithInputWorkflowInput) (WorkflowWithInputWorkflow, error)) func(workflow.Context, *WorkflowWithInputRequest) error {
	return func(ctx workflow.Context, req *WorkflowWithInputRequest) error {
		input := &WorkflowWithInputWorkflowInput{
			Req: req,
		}
		wf, err := ctor(ctx, input)
		if err != nil {
			return err
		}
		if initializable, ok := wf.(helpers.Initializable); ok {
			if err := initializable.Initialize(ctx); err != nil {
				return err
			}
		}
		{
			opts := workflow.UpdateHandlerOptions{}
			if err := workflow.SetUpdateHandlerWithOptions(ctx, UpdateWithInputUpdateName, wf.UpdateWithInput, opts); err != nil {
				return err
			}
		}
		return wf.Execute(ctx)
	}
}

// WorkflowWithInputWorkflowInput describes the input to a(n) test.option.v1.Test.WorkflowWithInput workflow constructor
type WorkflowWithInputWorkflowInput struct {
	Req *WorkflowWithInputRequest
}

// WorkflowWithInputWorkflow describes a(n) test.option.v1.Test.WorkflowWithInput workflow implementation
//
// workflow details: (id: "workflow-with-input:${! name.or(throw("name is required")) }")
type WorkflowWithInputWorkflow interface {
	// Execute defines the entrypoint to a(n) test.option.v1.Test.WorkflowWithInput workflow
	Execute(ctx workflow.Context) error

	// test.option.v1.Test.UpdateWithInput implements a(n) test.option.v1.Test.UpdateWithInput update handler
	UpdateWithInput(workflow.Context, *UpdateWithInputRequest) error
}

// WorkflowWithInputChild executes a child test.option.v1.Test.WorkflowWithInput workflow and blocks until error or response received
func WorkflowWithInputChild(ctx workflow.Context, req *WorkflowWithInputRequest, options ...*WorkflowWithInputChildOptions) error {
	childRun, err := WorkflowWithInputChildAsync(ctx, req, options...)
	if err != nil {
		return err
	}
	return childRun.Get(ctx)
}

// WorkflowWithInputChildAsync starts a child test.option.v1.Test.WorkflowWithInput workflow and returns a handle to the child workflow run
func WorkflowWithInputChildAsync(ctx workflow.Context, req *WorkflowWithInputRequest, options ...*WorkflowWithInputChildOptions) (*WorkflowWithInputChildRun, error) {
	var o *WorkflowWithInputChildOptions
	if len(options) > 0 && options[0] != nil {
		o = options[0]
	} else {
		o = NewWorkflowWithInputChildOptions()
	}
	opts, err := o.Build(ctx, req.ProtoReflect())
	if err != nil {
		return nil, fmt.Errorf("error initializing workflow.ChildWorkflowOptions: %w", err)
	}
	ctx = workflow.WithChildOptions(ctx, opts)
	if o.dc != nil {
		ctx = workflow.WithDataConverter(ctx, o.dc)
	}
	return &WorkflowWithInputChildRun{Future: workflow.ExecuteChildWorkflow(ctx, WorkflowWithInputWorkflowName, req)}, nil
}

// WorkflowWithInputChildOptions provides configuration for a child test.option.v1.Test.WorkflowWithInput workflow operation
type WorkflowWithInputChildOptions struct {
	options                  workflow.ChildWorkflowOptions
	executionTimeout         *time.Duration
	id                       *string
	idReusePolicy            enumsv1.WorkflowIdReusePolicy
	retryPolicy              *temporal.RetryPolicy
	runTimeout               *time.Duration
	searchAttributes         map[string]any
	taskQueue                *string
	taskTimeout              *time.Duration
	workflowIdConflictPolicy enumsv1.WorkflowIdConflictPolicy
	dc                       converter.DataConverter
	parentClosePolicy        enumsv1.ParentClosePolicy
	waitForCancellation      *bool
}

// NewWorkflowWithInputChildOptions initializes a new WorkflowWithInputChildOptions value
func NewWorkflowWithInputChildOptions() *WorkflowWithInputChildOptions {
	return &WorkflowWithInputChildOptions{}
}

// Build initializes a new go.temporal.io/sdk/workflow.ChildWorkflowOptions value with defaults and overrides applied
func (o *WorkflowWithInputChildOptions) Build(ctx workflow.Context, req protoreflect.Message) (workflow.ChildWorkflowOptions, error) {
	opts := o.options
	if v := o.id; v != nil {
		opts.WorkflowID = *v
	} else if opts.WorkflowID == "" {
		// wrap expression evaluation in local activity
		// more info: https://cludden.github.io/protoc-gen-go-temporal/docs/guides/patches#pv_64-expression-evaluation-local-activity
		if workflow.GetVersion(ctx, "cludden_protoc-gen-go-temporal_64_expression-evaluation-local-activity", workflow.DefaultVersion, 1) == 1 {
			lao := workflow.GetLocalActivityOptions(ctx)
			lao.ScheduleToCloseTimeout = time.Second * 10
			if err := workflow.ExecuteLocalActivity(workflow.WithLocalActivityOptions(ctx, lao), func(ctx context.Context) (string, error) {
				id, err := expression.EvalExpression(WorkflowWithInputIdexpression, req)
				if err != nil {
					return "", fmt.Errorf("error evaluating id expression for %q workflow: %w", WorkflowWithInputWorkflowName, err)
				}
				return id, nil
			}).Get(ctx, &opts.WorkflowID); err != nil {
				return opts, fmt.Errorf("error evaluating id expression for %q workflow: %w", WorkflowWithInputWorkflowName, err)
			}
		} else {
			id, err := expression.EvalExpression(WorkflowWithInputIdexpression, req)
			if err != nil {
				return opts, fmt.Errorf("error evaluating id expression for %q workflow: %w", WorkflowWithInputWorkflowName, err)
			}
			opts.WorkflowID = id
		}
	}
	if v := o.idReusePolicy; v != enumsv1.WORKFLOW_ID_REUSE_POLICY_UNSPECIFIED {
		opts.WorkflowIDReusePolicy = v
	} else if opts.WorkflowIDReusePolicy == enumsv1.WORKFLOW_ID_REUSE_POLICY_UNSPECIFIED {
		opts.WorkflowIDReusePolicy = enumsv1.WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE_FAILED_ONLY
	}
	if v := o.taskQueue; v != nil {
		opts.TaskQueue = *v
	} else if opts.TaskQueue == "" {
		opts.TaskQueue = "option-v2"
	}
	if v := o.retryPolicy; v != nil {
		opts.RetryPolicy = v
	} else if opts.RetryPolicy == nil {
		opts.RetryPolicy = &temporal.RetryPolicy{
			MaximumAttempts: int32(5),
		}
	}
	if v := o.searchAttributes; v != nil {
		opts.SearchAttributes = o.searchAttributes
	} else if opts.SearchAttributes == nil {
		// wrap expression evaluation in local activity
		// more info: https://cludden.github.io/protoc-gen-go-temporal/docs/guides/patches#pv_64-expression-evaluation-local-activity
		if workflow.GetVersion(ctx, "cludden_protoc-gen-go-temporal_64_expression-evaluation-local-activity", workflow.DefaultVersion, 1) == 1 {
			lao := workflow.GetLocalActivityOptions(ctx)
			lao.ScheduleToCloseTimeout = time.Second * 10
			if err := workflow.ExecuteLocalActivity(workflow.WithLocalActivityOptions(ctx, lao), func(ctx context.Context) (map[string]any, error) {
				structured, err := expression.ToStructured(req)
				if err != nil {
					return nil, fmt.Errorf("error serializing input for \"WorkflowWithInput\" search attribute mapping: %v", err)
				}
				result, err := WorkflowWithInputSearchAttributesMapping.Query(structured)
				if err != nil {
					return nil, fmt.Errorf("error executing \"WorkflowWithInput\" search attribute mapping: %v", err)
				}
				searchAttributes, ok := result.(map[string]any)
				if !ok {
					return nil, fmt.Errorf("expected \"WorkflowWithInput\" search attribute mapping to return map[string]any, got: %T", result)
				}
				return searchAttributes, nil
			}).Get(ctx, &opts.SearchAttributes); err != nil {
				return opts, fmt.Errorf("error evaluating search attributes for %q workflow: %w", WorkflowWithInputWorkflowName, err)
			}
		} else {
			structured, err := expression.ToStructured(req)
			if err != nil {
				return opts, fmt.Errorf("error serializing input for \"WorkflowWithInput\" search attribute mapping: %v", err)
			}
			result, err := WorkflowWithInputSearchAttributesMapping.Query(structured)
			if err != nil {
				return opts, fmt.Errorf("error executing \"WorkflowWithInput\" search attribute mapping: %v", err)
			}
			searchAttributes, ok := result.(map[string]any)
			if !ok {
				return opts, fmt.Errorf("expected \"WorkflowWithInput\" search attribute mapping to return map[string]any, got: %T", result)
			}
			opts.SearchAttributes = searchAttributes
		}
	}
	if v := o.executionTimeout; v != nil {
		opts.WorkflowExecutionTimeout = *v
	} else if opts.WorkflowExecutionTimeout == 0 {
		opts.WorkflowExecutionTimeout = 600000000000 // 10 minutes
	}
	if v := o.runTimeout; v != nil {
		opts.WorkflowRunTimeout = *v
	} else if opts.WorkflowRunTimeout == 0 {
		opts.WorkflowRunTimeout = 300000000000 // 5 minutes
	}
	if v := o.taskTimeout; v != nil {
		opts.WorkflowTaskTimeout = *v
	} else if opts.WorkflowTaskTimeout == 0 {
		opts.WorkflowTaskTimeout = 10000000000 // 10 seconds
	}
	if v := o.parentClosePolicy; v != enumsv1.PARENT_CLOSE_POLICY_UNSPECIFIED {
		opts.ParentClosePolicy = v
	} else if opts.ParentClosePolicy == enumsv1.PARENT_CLOSE_POLICY_UNSPECIFIED {
		opts.ParentClosePolicy = enumsv1.PARENT_CLOSE_POLICY_REQUEST_CANCEL
	}
	if v := o.waitForCancellation; v != nil {
		opts.WaitForCancellation = *v
	} else {
		opts.WaitForCancellation = true
	}
	return opts, nil
}

// WithChildWorkflowOptions sets the initial go.temporal.io/sdk/workflow.ChildWorkflowOptions
func (o *WorkflowWithInputChildOptions) WithChildWorkflowOptions(options workflow.ChildWorkflowOptions) *WorkflowWithInputChildOptions {
	o.options = options
	return o
}

// WithDataConverter registers a DataConverter for the child workflow
func (o *WorkflowWithInputChildOptions) WithDataConverter(dc converter.DataConverter) *WorkflowWithInputChildOptions {
	o.dc = dc
	return o
}

// WithExecutionTimeout sets the WorkflowExecutionTimeout value
func (o *WorkflowWithInputChildOptions) WithExecutionTimeout(d time.Duration) *WorkflowWithInputChildOptions {
	o.executionTimeout = &d
	return o
}

// WithID sets the WorkflowID value
func (o *WorkflowWithInputChildOptions) WithID(id string) *WorkflowWithInputChildOptions {
	o.id = &id
	return o
}

// WithIDReusePolicy sets the WorkflowIDReusePolicy value
func (o *WorkflowWithInputChildOptions) WithIDReusePolicy(policy enumsv1.WorkflowIdReusePolicy) *WorkflowWithInputChildOptions {
	o.idReusePolicy = policy
	return o
}

// WithParentClosePolicy sets the WorkflowIDReusePolicy value
func (o *WorkflowWithInputChildOptions) WithParentClosePolicy(policy enumsv1.ParentClosePolicy) *WorkflowWithInputChildOptions {
	o.parentClosePolicy = policy
	return o
}

// WithRetryPolicy sets the RetryPolicy value
func (o *WorkflowWithInputChildOptions) WithRetryPolicy(policy *temporal.RetryPolicy) *WorkflowWithInputChildOptions {
	o.retryPolicy = policy
	return o
}

// WithRunTimeout sets the WorkflowRunTimeout value
func (o *WorkflowWithInputChildOptions) WithRunTimeout(d time.Duration) *WorkflowWithInputChildOptions {
	o.runTimeout = &d
	return o
}

// WithSearchAttributes sets the SearchAttributes value
func (o *WorkflowWithInputChildOptions) WithSearchAttributes(sa map[string]any) *WorkflowWithInputChildOptions {
	o.searchAttributes = sa
	return o
}

// WithTaskTimeout sets the WorkflowTaskTimeout value
func (o *WorkflowWithInputChildOptions) WithTaskTimeout(d time.Duration) *WorkflowWithInputChildOptions {
	o.taskTimeout = &d
	return o
}

// WithTaskQueue sets the TaskQueue value
func (o *WorkflowWithInputChildOptions) WithTaskQueue(tq string) *WorkflowWithInputChildOptions {
	o.taskQueue = &tq
	return o
}

// WithWaitForCancellation sets the WaitForCancellation value
func (o *WorkflowWithInputChildOptions) WithWaitForCancellation(wait bool) *WorkflowWithInputChildOptions {
	o.waitForCancellation = &wait
	return o
}

// WithWorkflowIdConflictPolicy sets the WorkflowIdConflictPolicy value
func (o *WorkflowWithInputChildOptions) WithWorkflowIdConflictPolicy(policy enumsv1.WorkflowIdConflictPolicy) *WorkflowWithInputChildOptions {
	o.workflowIdConflictPolicy = policy
	return o
}

// WorkflowWithInputChildRun describes a child WorkflowWithInput workflow run
type WorkflowWithInputChildRun struct {
	Future workflow.ChildWorkflowFuture
}

// Get blocks until the workflow is completed, returning the response value
func (r *WorkflowWithInputChildRun) Get(ctx workflow.Context) error {
	if err := r.Future.Get(ctx, nil); err != nil {
		return err
	}
	return nil
}

// Select adds this completion to the selector. Callback can be nil.
func (r *WorkflowWithInputChildRun) Select(sel workflow.Selector, fn func(*WorkflowWithInputChildRun)) workflow.Selector {
	return sel.AddFuture(r.Future, func(workflow.Future) {
		if fn != nil {
			fn(r)
		}
	})
}

// SelectStart adds waiting for start to the selector. Callback can be nil.
func (r *WorkflowWithInputChildRun) SelectStart(sel workflow.Selector, fn func(*WorkflowWithInputChildRun)) workflow.Selector {
	return sel.AddFuture(r.Future.GetChildWorkflowExecution(), func(workflow.Future) {
		if fn != nil {
			fn(r)
		}
	})
}

// WaitStart waits for the child workflow to start
func (r *WorkflowWithInputChildRun) WaitStart(ctx workflow.Context) (*workflow.Execution, error) {
	var exec workflow.Execution
	if err := r.Future.GetChildWorkflowExecution().Get(ctx, &exec); err != nil {
		return nil, err
	}
	return &exec, nil
}

// TestActivities describes available worker activities
type TestActivities interface {
	// test.option.v1.Test.ActivityWithInput implements a(n) test.option.v1.Test.ActivityWithInput activity definition
	ActivityWithInput(ctx context.Context, req *ActivityWithInputRequest) (*ActivityWithInputResponse, error)
}

// RegisterTestActivities registers activities with a worker
func RegisterTestActivities(r worker.ActivityRegistry, activities TestActivities) {
	RegisterActivityWithInputActivity(r, activities.ActivityWithInput)
}

// RegisterActivityWithInputActivity registers a test.option.v1.Test.ActivityWithInput activity
func RegisterActivityWithInputActivity(r worker.ActivityRegistry, fn func(context.Context, *ActivityWithInputRequest) (*ActivityWithInputResponse, error)) {
	r.RegisterActivityWithOptions(fn, activity.RegisterOptions{
		Name: ActivityWithInputActivityName,
	})
}

// ActivityWithInputFuture describes a(n) test.option.v1.Test.ActivityWithInput activity execution
type ActivityWithInputFuture struct {
	Future workflow.Future
}

// Get blocks on the activity's completion, returning the response
func (f *ActivityWithInputFuture) Get(ctx workflow.Context) (*ActivityWithInputResponse, error) {
	var resp ActivityWithInputResponse
	if err := f.Future.Get(ctx, &resp); err != nil {
		return nil, err
	}
	return &resp, nil
}

// Select adds the activity's completion to the selector, callback can be nil
func (f *ActivityWithInputFuture) Select(sel workflow.Selector, fn func(*ActivityWithInputFuture)) workflow.Selector {
	return sel.AddFuture(f.Future, func(workflow.Future) {
		if fn != nil {
			fn(f)
		}
	})
}

// ActivityWithInput executes a(n) test.option.v1.Test.ActivityWithInput activity
func ActivityWithInput(ctx workflow.Context, req *ActivityWithInputRequest, options ...*ActivityWithInputActivityOptions) (*ActivityWithInputResponse, error) {
	return ActivityWithInputAsync(ctx, req, options...).Get(ctx)
}

// ActivityWithInputAsync executes a(n) test.option.v1.Test.ActivityWithInput activity (asynchronously)
func ActivityWithInputAsync(ctx workflow.Context, req *ActivityWithInputRequest, options ...*ActivityWithInputActivityOptions) *ActivityWithInputFuture {
	var o *ActivityWithInputActivityOptions
	if len(options) > 0 && options[0] != nil {
		o = options[0]
	} else {
		o = NewActivityWithInputActivityOptions()
	}
	var err error
	if ctx, err = o.Build(ctx); err != nil {
		errF, errS := workflow.NewFuture(ctx)
		errS.SetError(err)
		return &ActivityWithInputFuture{Future: errF}
	}
	activity := ActivityWithInputActivityName
	if o.dc != nil {
		ctx = workflow.WithDataConverter(ctx, o.dc)
	}
	future := &ActivityWithInputFuture{Future: workflow.ExecuteActivity(ctx, activity, req)}
	return future
}

// ActivityWithInputLocal executes a(n) test.option.v1.Test.ActivityWithInput activity (locally)
func ActivityWithInputLocal(ctx workflow.Context, req *ActivityWithInputRequest, options ...*ActivityWithInputLocalActivityOptions) (*ActivityWithInputResponse, error) {
	return ActivityWithInputLocalAsync(ctx, req, options...).Get(ctx)
}

// ActivityWithInputLocalAsync executes a(n) test.option.v1.Test.ActivityWithInput activity (asynchronously, locally)
func ActivityWithInputLocalAsync(ctx workflow.Context, req *ActivityWithInputRequest, options ...*ActivityWithInputLocalActivityOptions) *ActivityWithInputFuture {
	var o *ActivityWithInputLocalActivityOptions
	if len(options) > 0 && options[0] != nil {
		o = options[0]
	} else {
		o = NewActivityWithInputLocalActivityOptions()
	}
	var err error
	if ctx, err = o.Build(ctx); err != nil {
		errF, errS := workflow.NewFuture(ctx)
		errS.SetError(err)
		return &ActivityWithInputFuture{Future: errF}
	}
	var activity any
	if o.fn != nil {
		activity = o.fn
	} else {
		activity = ActivityWithInputActivityName
	}
	if o.dc != nil {
		ctx = workflow.WithDataConverter(ctx, o.dc)
	}
	future := &ActivityWithInputFuture{Future: workflow.ExecuteLocalActivity(ctx, activity, req)}
	return future
}

// ActivityWithInputActivityOptions provides configuration for a(n) test.option.v1.Test.ActivityWithInput activity
type ActivityWithInputActivityOptions struct {
	options                workflow.ActivityOptions
	retryPolicy            *temporal.RetryPolicy
	scheduleToCloseTimeout *time.Duration
	startToCloseTimeout    *time.Duration
	dc                     converter.DataConverter
	heartbeatTimeout       *time.Duration
	scheduleToStartTimeout *time.Duration
	taskQueue              *string
	waitForCancellation    *bool
}

// NewActivityWithInputActivityOptions initializes a new ActivityWithInputActivityOptions value
func NewActivityWithInputActivityOptions() *ActivityWithInputActivityOptions {
	return &ActivityWithInputActivityOptions{}
}

// Build initializes a workflow.Context with appropriate ActivityOptions values derived from schema defaults and any user-defined overrides
func (o *ActivityWithInputActivityOptions) Build(ctx workflow.Context) (workflow.Context, error) {
	opts := o.options
	if v := o.heartbeatTimeout; v != nil {
		opts.HeartbeatTimeout = *v
	} else if opts.HeartbeatTimeout == 0 {
		opts.HeartbeatTimeout = 30000000000 // 30 seconds
	}
	if v := o.retryPolicy; v != nil {
		opts.RetryPolicy = v
	} else if opts.RetryPolicy == nil {
		opts.RetryPolicy = &temporal.RetryPolicy{MaximumInterval: 5000000000}
	}
	if v := o.scheduleToCloseTimeout; v != nil {
		opts.ScheduleToCloseTimeout = *v
	} else if opts.ScheduleToCloseTimeout == 0 {
		opts.ScheduleToCloseTimeout = 120000000000 // 2 minutes
	}
	if v := o.scheduleToStartTimeout; v != nil {
		opts.ScheduleToStartTimeout = *v
	} else if opts.ScheduleToStartTimeout == 0 {
		opts.ScheduleToStartTimeout = 10000000000 // 10 seconds
	}
	if v := o.startToCloseTimeout; v != nil {
		opts.StartToCloseTimeout = *v
	} else if opts.StartToCloseTimeout == 0 {
		opts.StartToCloseTimeout = 60000000000 // 1 minute
	}
	if v := o.taskQueue; v != nil {
		opts.TaskQueue = *v
	} else if opts.TaskQueue == "" {
		opts.TaskQueue = "option-v2"
	}
	if v := o.waitForCancellation; v != nil {
		opts.WaitForCancellation = *v
	} else if !opts.WaitForCancellation {
		opts.WaitForCancellation = true
	}
	return workflow.WithActivityOptions(ctx, opts), nil
}

// WithActivityOptions specifies an initial ActivityOptions value to which defaults will be applied
func (o *ActivityWithInputActivityOptions) WithActivityOptions(options workflow.ActivityOptions) *ActivityWithInputActivityOptions {
	o.options = options
	return o
}

// WithDataConverter registers a DataConverter for the (local) activity
func (o *ActivityWithInputActivityOptions) WithDataConverter(dc converter.DataConverter) *ActivityWithInputActivityOptions {
	o.dc = dc
	return o
}

// WithHeartbeatTimeout sets the HeartbeatTimeout value
func (o *ActivityWithInputActivityOptions) WithHeartbeatTimeout(d time.Duration) *ActivityWithInputActivityOptions {
	o.heartbeatTimeout = &d
	return o
}

// WithRetryPolicy sets the RetryPolicy value
func (o *ActivityWithInputActivityOptions) WithRetryPolicy(policy *temporal.RetryPolicy) *ActivityWithInputActivityOptions {
	o.retryPolicy = policy
	return o
}

// WithScheduleToCloseTimeout sets the ScheduleToCloseTimeout value
func (o *ActivityWithInputActivityOptions) WithScheduleToCloseTimeout(d time.Duration) *ActivityWithInputActivityOptions {
	o.scheduleToCloseTimeout = &d
	return o
}

// WithScheduleToStartTimeout sets the ScheduleToStartTimeout value
func (o *ActivityWithInputActivityOptions) WithScheduleToStartTimeout(d time.Duration) *ActivityWithInputActivityOptions {
	o.scheduleToStartTimeout = &d
	return o
}

// WithStartToCloseTimeout sets the StartToCloseTimeout value
func (o *ActivityWithInputActivityOptions) WithStartToCloseTimeout(d time.Duration) *ActivityWithInputActivityOptions {
	o.startToCloseTimeout = &d
	return o
}

// WithTaskQueue sets the TaskQueue value
func (o *ActivityWithInputActivityOptions) WithTaskQueue(tq string) *ActivityWithInputActivityOptions {
	o.taskQueue = &tq
	return o
}

// WithWaitForCancellation sets the WaitForCancellation value
func (o *ActivityWithInputActivityOptions) WithWaitForCancellation(wait bool) *ActivityWithInputActivityOptions {
	o.waitForCancellation = &wait
	return o
}

// ActivityWithInputLocalActivityOptions provides configuration for a(n) test.option.v1.Test.ActivityWithInput activity
type ActivityWithInputLocalActivityOptions struct {
	options                workflow.LocalActivityOptions
	retryPolicy            *temporal.RetryPolicy
	scheduleToCloseTimeout *time.Duration
	startToCloseTimeout    *time.Duration
	dc                     converter.DataConverter
	fn                     func(context.Context, *ActivityWithInputRequest) (*ActivityWithInputResponse, error)
}

// NewActivityWithInputLocalActivityOptions initializes a new ActivityWithInputLocalActivityOptions value
func NewActivityWithInputLocalActivityOptions() *ActivityWithInputLocalActivityOptions {
	return &ActivityWithInputLocalActivityOptions{}
}

// Build initializes a workflow.Context with appropriate LocalActivityOptions values derived from schema defaults and any user-defined overrides
func (o *ActivityWithInputLocalActivityOptions) Build(ctx workflow.Context) (workflow.Context, error) {
	opts := o.options
	if v := o.retryPolicy; v != nil {
		opts.RetryPolicy = v
	} else if opts.RetryPolicy == nil {
		opts.RetryPolicy = &temporal.RetryPolicy{MaximumInterval: 5000000000}
	}
	if v := o.scheduleToCloseTimeout; v != nil {
		opts.ScheduleToCloseTimeout = *v
	} else if opts.ScheduleToCloseTimeout == 0 {
		opts.ScheduleToCloseTimeout = 120000000000 // 2 minutes
	}
	if v := o.startToCloseTimeout; v != nil {
		opts.StartToCloseTimeout = *v
	} else if opts.StartToCloseTimeout == 0 {
		opts.StartToCloseTimeout = 60000000000 // 1 minute
	}
	return workflow.WithLocalActivityOptions(ctx, opts), nil
}

// Local specifies a custom test.option.v1.Test.ActivityWithInput implementation
func (o *ActivityWithInputLocalActivityOptions) Local(fn func(context.Context, *ActivityWithInputRequest) (*ActivityWithInputResponse, error)) *ActivityWithInputLocalActivityOptions {
	o.fn = fn
	return o
}

// WithLocalActivityOptions specifies an initial LocalActivityOptions value to which defaults will be applied
func (o *ActivityWithInputLocalActivityOptions) WithLocalActivityOptions(options workflow.LocalActivityOptions) *ActivityWithInputLocalActivityOptions {
	o.options = options
	return o
}

// WithDataConverter registers a DataConverter for the (local) activity
func (o *ActivityWithInputLocalActivityOptions) WithDataConverter(dc converter.DataConverter) *ActivityWithInputLocalActivityOptions {
	o.dc = dc
	return o
}

// WithRetryPolicy sets the RetryPolicy value
func (o *ActivityWithInputLocalActivityOptions) WithRetryPolicy(policy *temporal.RetryPolicy) *ActivityWithInputLocalActivityOptions {
	o.retryPolicy = policy
	return o
}

// WithScheduleToCloseTimeout sets the ScheduleToCloseTimeout value
func (o *ActivityWithInputLocalActivityOptions) WithScheduleToCloseTimeout(d time.Duration) *ActivityWithInputLocalActivityOptions {
	o.scheduleToCloseTimeout = &d
	return o
}

// WithStartToCloseTimeout sets the StartToCloseTimeout value
func (o *ActivityWithInputLocalActivityOptions) WithStartToCloseTimeout(d time.Duration) *ActivityWithInputLocalActivityOptions {
	o.startToCloseTimeout = &d
	return o
}

// TestClient provides a testsuite-compatible Client
type TestTestClient struct {
	env       *testsuite.TestWorkflowEnvironment
	workflows TestWorkflows
}

var _ TestClient = &TestTestClient{}

// NewTestTestClient initializes a new TestTestClient value
func NewTestTestClient(env *testsuite.TestWorkflowEnvironment, workflows TestWorkflows, activities TestActivities) *TestTestClient {
	if workflows != nil {
		RegisterTestWorkflows(env, workflows)
	}
	if activities != nil {
		RegisterTestActivities(env, activities)
	}
	return &TestTestClient{env, workflows}
}

// WorkflowWithInput executes a(n) test.option.v1.Test.WorkflowWithInput workflow in the test environment
func (c *TestTestClient) WorkflowWithInput(ctx context.Context, req *WorkflowWithInputRequest, opts ...*WorkflowWithInputOptions) error {
	run, err := c.WorkflowWithInputAsync(ctx, req, opts...)
	if err != nil {
		return err
	}
	return run.Get(ctx)
}

// WorkflowWithInputAsync executes a(n) test.option.v1.Test.WorkflowWithInput workflow in the test environment
func (c *TestTestClient) WorkflowWithInputAsync(ctx context.Context, req *WorkflowWithInputRequest, options ...*WorkflowWithInputOptions) (WorkflowWithInputRun, error) {
	var o *WorkflowWithInputOptions
	if len(options) > 0 && options[0] != nil {
		o = options[0]
	} else {
		o = NewWorkflowWithInputOptions()
	}
	opts, err := o.Build(req.ProtoReflect())
	if err != nil {
		return nil, fmt.Errorf("error initializing client.StartWorkflowOptions: %w", err)
	}
	return &testWorkflowWithInputRun{client: c, env: c.env, opts: &opts, req: req, workflows: c.workflows}, nil
}

// GetWorkflowWithInput is a noop
func (c *TestTestClient) GetWorkflowWithInput(ctx context.Context, workflowID string, runID string) WorkflowWithInputRun {
	return &testWorkflowWithInputRun{env: c.env, workflows: c.workflows}
}

// CancelWorkflow requests cancellation of an existing workflow execution
func (c *TestTestClient) CancelWorkflow(ctx context.Context, workflowID string, runID string) error {
	c.env.CancelWorkflow()
	return nil
}

// TerminateWorkflow terminates an existing workflow execution
func (c *TestTestClient) TerminateWorkflow(ctx context.Context, workflowID string, runID string, reason string, details ...interface{}) error {
	return c.CancelWorkflow(ctx, workflowID, runID)
}

// UpdateWithInput executes a(n) test.option.v1.Test.UpdateWithInput update in the test environment
func (c *TestTestClient) UpdateWithInput(ctx context.Context, workflowID string, runID string, req *UpdateWithInputRequest, opts ...*UpdateWithInputOptions) error {
	options := NewUpdateWithInputOptions()
	if len(opts) > 0 && opts[0].Options != nil {
		options = opts[0]
	}
	options.Options.WaitForStage = client.WorkflowUpdateStageCompleted
	handle, err := c.UpdateWithInputAsync(ctx, workflowID, runID, req, options)
	if err != nil {
		return err
	}
	return handle.Get(ctx)
}

// UpdateWithInputAsync executes a(n) test.option.v1.Test.UpdateWithInput update in the test environment
func (c *TestTestClient) UpdateWithInputAsync(ctx context.Context, workflowID string, runID string, req *UpdateWithInputRequest, opts ...*UpdateWithInputOptions) (UpdateWithInputHandle, error) {
	var o *UpdateWithInputOptions
	if len(opts) > 0 && opts[0] != nil {
		o = opts[0]
	} else {
		o = NewUpdateWithInputOptions()
	}
	options, err := o.Build(workflowID, runID, req)
	if err != nil {
		return nil, fmt.Errorf("error initializing UpdateWorkflowWithOptions: %w", err)
	}

	if options.UpdateID == "" {
		options.UpdateID = uuid.New().String()
	}

	uc := testutil.NewUpdateCallbacks()
	c.env.UpdateWorkflow(UpdateWithInputUpdateName, options.UpdateID, uc, req)
	return &testUpdateWithInputHandle{
		callbacks:  uc,
		env:        c.env,
		opts:       options,
		runID:      runID,
		workflowID: workflowID,
		req:        req,
	}, nil
}

// GetUpdateWithInput retrieves a handle to an existing test.option.v1.Test.UpdateWithInput update
func (c *TestTestClient) GetUpdateWithInput(ctx context.Context, req client.GetWorkflowUpdateHandleOptions) (UpdateWithInputHandle, error) {
	return nil, errors.New("unimplemented")
}

var _ UpdateWithInputHandle = &testUpdateWithInputHandle{}

// testUpdateWithInputHandle provides an internal implementation of a(n) UpdateWithInputHandle
type testUpdateWithInputHandle struct {
	callbacks  *testutil.UpdateCallbacks
	env        *testsuite.TestWorkflowEnvironment
	opts       *client.UpdateWorkflowOptions
	req        *UpdateWithInputRequest
	runID      string
	workflowID string
}

// Get retrieves a test test.option.v1.Test.UpdateWithInput update result
func (h *testUpdateWithInputHandle) Get(ctx context.Context) error {
	if _, err := h.callbacks.Get(ctx); err != nil {
		return err
	} else {
		return nil
	}
}

// RunID implementation
func (h *testUpdateWithInputHandle) RunID() string {
	return h.runID
}

// UpdateID implementation
func (h *testUpdateWithInputHandle) UpdateID() string {
	if h.opts != nil {
		return h.opts.UpdateID
	}
	return ""
}

// WorkflowID implementation
func (h *testUpdateWithInputHandle) WorkflowID() string {
	return h.workflowID
}

var _ WorkflowWithInputRun = &testWorkflowWithInputRun{}

// testWorkflowWithInputRun provides convenience methods for interacting with a(n) test.option.v1.Test.WorkflowWithInput workflow in the test environment
type testWorkflowWithInputRun struct {
	client    *TestTestClient
	env       *testsuite.TestWorkflowEnvironment
	isStarted atomic.Bool
	opts      *client.StartWorkflowOptions
	req       *WorkflowWithInputRequest
	workflows TestWorkflows
}

// Cancel requests cancellation of a workflow in execution, returning an error if applicable
func (r *testWorkflowWithInputRun) Cancel(ctx context.Context) error {
	return r.client.CancelWorkflow(ctx, r.ID(), r.RunID())
}

// Get retrieves a test test.option.v1.Test.WorkflowWithInput workflow result
func (r *testWorkflowWithInputRun) Get(context.Context) error {
	if r.isStarted.CompareAndSwap(false, true) {
		r.env.ExecuteWorkflow(WorkflowWithInputWorkflowName, r.req)
	}
	if !r.env.IsWorkflowCompleted() {
		return errors.New("workflow in progress")
	}
	if err := r.env.GetWorkflowError(); err != nil {
		return err
	}
	return nil
}

// ID returns a test test.option.v1.Test.WorkflowWithInput workflow run's workflow ID
func (r *testWorkflowWithInputRun) ID() string {
	if r.opts != nil {
		return r.opts.ID
	}
	return ""
}

// Run noop implementation
func (r *testWorkflowWithInputRun) Run() client.WorkflowRun {
	return nil
}

// RunID noop implementation
func (r *testWorkflowWithInputRun) RunID() string {
	return ""
}

// Terminate terminates a workflow in execution, returning an error if applicable
func (r *testWorkflowWithInputRun) Terminate(ctx context.Context, reason string, details ...interface{}) error {
	return r.client.TerminateWorkflow(ctx, r.ID(), r.RunID(), reason, details...)
}

// UpdateWithInput executes a(n) test.option.v1.Test.UpdateWithInput update against a test test.option.v1.Test.WorkflowWithInput workflow
func (r *testWorkflowWithInputRun) UpdateWithInput(ctx context.Context, req *UpdateWithInputRequest, opts ...*UpdateWithInputOptions) error {
	return r.client.UpdateWithInput(ctx, r.ID(), r.RunID(), req, opts...)
}

// UpdateWithInputAsync executes a(n) test.option.v1.Test.UpdateWithInput update against a test test.option.v1.Test.WorkflowWithInput workflow
func (r *testWorkflowWithInputRun) UpdateWithInputAsync(ctx context.Context, req *UpdateWithInputRequest, opts ...*UpdateWithInputOptions) (UpdateWithInputHandle, error) {
	return r.client.UpdateWithInputAsync(ctx, r.ID(), r.RunID(), req, opts...)
}

// TestCliOptions describes runtime configuration for test.option.v1.Test cli
type TestCliOptions struct {
	after            func(*v2.Context) error
	before           func(*v2.Context) error
	clientForCommand func(*v2.Context) (client.Client, error)
	worker           func(*v2.Context, client.Client) (worker.Worker, error)
}

// NewTestCliOptions initializes a new TestCliOptions value
func NewTestCliOptions() *TestCliOptions {
	return &TestCliOptions{}
}

// WithAfter injects a custom After hook to be run after any command invocation
func (opts *TestCliOptions) WithAfter(fn func(*v2.Context) error) *TestCliOptions {
	opts.after = fn
	return opts
}

// WithBefore injects a custom Before hook to be run prior to any command invocation
func (opts *TestCliOptions) WithBefore(fn func(*v2.Context) error) *TestCliOptions {
	opts.before = fn
	return opts
}

// WithClient provides a Temporal client factory for use by commands
func (opts *TestCliOptions) WithClient(fn func(*v2.Context) (client.Client, error)) *TestCliOptions {
	opts.clientForCommand = fn
	return opts
}

// WithWorker provides an method for initializing a worker
func (opts *TestCliOptions) WithWorker(fn func(*v2.Context, client.Client) (worker.Worker, error)) *TestCliOptions {
	opts.worker = fn
	return opts
}

// NewTestCli initializes a cli for a(n) test.option.v1.Test service
func NewTestCli(options ...*TestCliOptions) (*v2.App, error) {
	commands, err := newTestCommands(options...)
	if err != nil {
		return nil, fmt.Errorf("error initializing subcommands: %w", err)
	}
	return &v2.App{
		Name:                      "test",
		Commands:                  commands,
		DisableSliceFlagSeparator: true,
	}, nil
}

// NewTestCliCommand initializes a cli command for a test.option.v1.Test service with subcommands for each query, signal, update, and workflow
func NewTestCliCommand(options ...*TestCliOptions) (*v2.Command, error) {
	subcommands, err := newTestCommands(options...)
	if err != nil {
		return nil, fmt.Errorf("error initializing subcommands: %w", err)
	}
	return &v2.Command{
		Name:        "test",
		Subcommands: subcommands,
	}, nil
}

// newTestCommands initializes (sub)commands for a test.option.v1.Test cli or command
func newTestCommands(options ...*TestCliOptions) ([]*v2.Command, error) {
	opts := &TestCliOptions{}
	if len(options) > 0 {
		opts = options[0]
	}
	if opts.clientForCommand == nil {
		opts.clientForCommand = func(*v2.Context) (client.Client, error) {
			return client.Dial(client.Options{})
		}
	}
	commands := []*v2.Command{
		{
			Name:                   "update-with-input",
			Usage:                  "executes a(n) test.option.v1.Test.UpdateWithInput update",
			Category:               "UPDATES",
			UseShortOptionHandling: true,
			Before:                 opts.before,
			After:                  opts.after,
			Flags: []v2.Flag{
				&v2.BoolFlag{
					Name:    "detach",
					Usage:   "run workflow update in the background and print workflow, execution, and udpate id",
					Aliases: []string{"d"},
				},
				&v2.StringFlag{
					Name:     "workflow-id",
					Usage:    "workflow id",
					Required: true,
					Aliases:  []string{"w"},
				},
				&v2.StringFlag{
					Name:    "run-id",
					Usage:   "run id",
					Aliases: []string{"r"},
				},
				&v2.StringFlag{
					Name:     "input-file",
					Usage:    "path to json-formatted input file",
					Aliases:  []string{"f"},
					Category: "INPUT",
				},
				&v2.StringFlag{
					Name:     "name",
					Usage:    "set the value of the operation's \"Name\" parameter",
					Category: "INPUT",
				},
			},
			Action: func(cmd *v2.Context) error {
				c, err := opts.clientForCommand(cmd)
				if err != nil {
					return fmt.Errorf("error initializing client for command: %w", err)
				}
				defer c.Close()
				client := NewTestClient(c)
				req, err := UnmarshalCliFlagsToUpdateWithInputRequest(cmd, helpers.UnmarshalCliFlagsOptions{FromFile: "input-file"})
				if err != nil {
					return fmt.Errorf("error unmarshalling request: %w", err)
				}
				handle, err := client.UpdateWithInputAsync(cmd.Context, cmd.String("workflow-id"), cmd.String("run-id"), req)
				if err != nil {
					return fmt.Errorf("error executing %s update: %w", UpdateWithInputUpdateName, err)
				}
				if cmd.Bool("detach") {
					fmt.Println("success")
					fmt.Printf("workflow id: %s\n", handle.WorkflowID())
					fmt.Printf("run id: %s\n", handle.RunID())
					fmt.Printf("update id: %s\n", handle.UpdateID())
					return nil
				}
				if err := handle.Get(cmd.Context); err != nil {
					return err
				} else {
					return nil
				}
			},
		},
		{
			Name:                   "workflow-with-input",
			Usage:                  "executes a(n) test.option.v1.Test.WorkflowWithInput workflow",
			Category:               "WORKFLOWS",
			UseShortOptionHandling: true,
			Before:                 opts.before,
			After:                  opts.after,
			Flags: []v2.Flag{
				&v2.BoolFlag{
					Name:    "detach",
					Usage:   "run workflow in the background and print workflow and execution id",
					Aliases: []string{"d"},
				},
				&v2.StringFlag{
					Name:    "task-queue",
					Usage:   "task queue name",
					Aliases: []string{"t"},
					EnvVars: []string{"TEMPORAL_TASK_QUEUE_NAME", "TEMPORAL_TASK_QUEUE", "TASK_QUEUE_NAME", "TASK_QUEUE"},
					Value:   "option-v2",
				},
				&v2.StringFlag{
					Name:     "input-file",
					Usage:    "path to json-formatted input file",
					Aliases:  []string{"f"},
					Category: "INPUT",
				},
				&v2.StringFlag{
					Name:     "name",
					Usage:    "set the value of the operation's \"Name\" parameter",
					Category: "INPUT",
				},
			},
			Action: func(cmd *v2.Context) error {
				tc, err := opts.clientForCommand(cmd)
				if err != nil {
					return fmt.Errorf("error initializing client for command: %w", err)
				}
				defer tc.Close()
				c := NewTestClient(tc)
				req, err := UnmarshalCliFlagsToWorkflowWithInputRequest(cmd, helpers.UnmarshalCliFlagsOptions{FromFile: "input-file"})
				if err != nil {
					return fmt.Errorf("error unmarshalling request: %w", err)
				}
				opts := client.StartWorkflowOptions{}
				if tq := cmd.String("task-queue"); tq != "" {
					opts.TaskQueue = tq
				}
				run, err := c.WorkflowWithInputAsync(cmd.Context, req, NewWorkflowWithInputOptions().WithStartWorkflowOptions(opts))
				if err != nil {
					return fmt.Errorf("error starting %s workflow: %w", WorkflowWithInputWorkflowName, err)
				}
				if cmd.Bool("detach") {
					fmt.Println("success")
					fmt.Printf("workflow id: %s\n", run.ID())
					fmt.Printf("run id: %s\n", run.RunID())
					return nil
				}
				if err := run.Get(cmd.Context); err != nil {
					return err
				} else {
					return nil
				}
			},
		},
	}
	if opts.worker != nil {
		commands = append(commands, []*v2.Command{
			{
				Name:                   "worker",
				Usage:                  "runs a test.option.v1.Test worker process",
				UseShortOptionHandling: true,
				Before:                 opts.before,
				After:                  opts.after,
				Action: func(cmd *v2.Context) error {
					c, err := opts.clientForCommand(cmd)
					if err != nil {
						return fmt.Errorf("error initializing client for command: %w", err)
					}
					defer c.Close()
					w, err := opts.worker(cmd, c)
					if opts.worker != nil {
						if err != nil {
							return fmt.Errorf("error initializing worker: %w", err)
						}
					}
					if err := w.Start(); err != nil {
						return fmt.Errorf("error starting worker: %w", err)
					}
					defer w.Stop()
					<-cmd.Context.Done()
					return nil
				},
			},
		}...)
	}
	sort.Slice(commands, func(i, j int) bool {
		return commands[i].Name < commands[j].Name
	})
	return commands, nil
}

// UnmarshalCliFlagsToUpdateWithInputRequest unmarshals a UpdateWithInputRequest from command line flags
func UnmarshalCliFlagsToUpdateWithInputRequest(cmd *v2.Context, options ...helpers.UnmarshalCliFlagsOptions) (*UpdateWithInputRequest, error) {
	opts := helpers.FlattenUnmarshalCliFlagsOptions(options...)
	var result UpdateWithInputRequest
	if opts.FromFile != "" && cmd.IsSet(opts.FromFile) {
		f, err := gohomedir.Expand(cmd.String(opts.FromFile))
		if err != nil {
			f = cmd.String(opts.FromFile)
		}
		b, err := os.ReadFile(f)
		if err != nil {
			return nil, fmt.Errorf("error reading %s: %w", opts.FromFile, err)
		}
		if err := protojson.Unmarshal(b, &result); err != nil {
			return nil, fmt.Errorf("error parsing %s json: %w", opts.FromFile, err)
		}
	}
	if flag := opts.FlagName("name"); cmd.IsSet(flag) {
		value := cmd.String(flag)
		result.Name = value
	}
	return &result, nil
}

// UnmarshalCliFlagsToWorkflowWithInputRequest unmarshals a WorkflowWithInputRequest from command line flags
func UnmarshalCliFlagsToWorkflowWithInputRequest(cmd *v2.Context, options ...helpers.UnmarshalCliFlagsOptions) (*WorkflowWithInputRequest, error) {
	opts := helpers.FlattenUnmarshalCliFlagsOptions(options...)
	var result WorkflowWithInputRequest
	if opts.FromFile != "" && cmd.IsSet(opts.FromFile) {
		f, err := gohomedir.Expand(cmd.String(opts.FromFile))
		if err != nil {
			f = cmd.String(opts.FromFile)
		}
		b, err := os.ReadFile(f)
		if err != nil {
			return nil, fmt.Errorf("error reading %s: %w", opts.FromFile, err)
		}
		if err := protojson.Unmarshal(b, &result); err != nil {
			return nil, fmt.Errorf("error parsing %s json: %w", opts.FromFile, err)
		}
	}
	if flag := opts.FlagName("name"); cmd.IsSet(flag) {
		value := cmd.String(flag)
		result.Name = value
	}
	return &result, nil
}

// WithTestSchemeTypes registers all Test protobuf types with the given scheme
func WithTestSchemeTypes() scheme.Option {
	return func(s *scheme.Scheme) {
		s.RegisterType(File_test_option_v1_option_proto.Messages().ByName("ActivityWithInputRequest"))
		s.RegisterType(File_test_option_v1_option_proto.Messages().ByName("ActivityWithInputResponse"))
		s.RegisterType(File_test_option_v1_option_proto.Messages().ByName("UpdateWithInputRequest"))
		s.RegisterType(File_test_option_v1_option_proto.Messages().ByName("WorkflowWithInputRequest"))
	}
}
