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

import (
	"bytes"
	"context"
	"encoding/json"
	"errors"
	"fmt"
	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"
	cliv3 "github.com/urfave/cli/v3"
	enumsv1 "go.temporal.io/api/enums/v1"
	serviceerror "go.temporal.io/api/serviceerror"
	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"
	timestamppb "google.golang.org/protobuf/types/known/timestamppb"
	"log/slog"
	"os"
	"sort"
	"strings"
	"sync"
	"sync/atomic"
	"time"
)

// ExampleServiceTaskQueue is the default task-queue for a test.cliv3.ExampleService worker
var ExampleServiceTaskQueue = "example-cliv3"

// test.cliv3.ExampleService workflow names
const (
	CreateFooWorkflowName = "test.cliv3.CreateFoo"
)

// test.cliv3.ExampleService query names
const (
	GetFooQueryName = "test.cliv3.GetFoo"
)

// test.cliv3.ExampleService signal names
const (
	SignalFooSignalName = "test.cliv3.SignalFoo"
)

// test.cliv3.ExampleService update names
const (
	UpdateFooUpdateName = "test.cliv3.UpdateFoo"
)

// ExampleServiceClient describes a client for a(n) test.cliv3.ExampleService worker
type ExampleServiceClient interface {
	// CreateFoo executes a(n) test.cliv3.CreateFoo workflow and blocks until error or response received
	CreateFoo(ctx context.Context, req *CreateFooInput, opts ...*CreateFooOptions) (*CreateFooOutput, error)

	// CreateFooAsync starts a(n) test.cliv3.CreateFoo workflow and returns a handle to the workflow run
	CreateFooAsync(ctx context.Context, req *CreateFooInput, opts ...*CreateFooOptions) (CreateFooRun, error)

	// GetCreateFoo retrieves a handle to an existing test.cliv3.CreateFoo workflow execution
	GetCreateFoo(ctx context.Context, workflowID string, runID string) CreateFooRun

	// CreateFooWithSignalFoo sends a(n) test.cliv3.SignalFoo signal to a(n) test.cliv3.CreateFoo workflow, starting it if necessary, and blocks until workflow completion
	CreateFooWithSignalFoo(ctx context.Context, req *CreateFooInput, signal *SignalFooInput, opts ...*CreateFooOptions) (*CreateFooOutput, error)

	// CreateFooWithSignalFooAsync sends a(n) test.cliv3.SignalFoo signal to a(n) test.cliv3.CreateFoo workflow, starting it if necessary, and returns a handle to the workflow execution
	CreateFooWithSignalFooAsync(ctx context.Context, req *CreateFooInput, signal *SignalFooInput, opts ...*CreateFooOptions) (CreateFooRun, error)

	// CreateFooWithUpdateFoo executes a(n) test.cliv3.UpdateFoo update on a(n) test.cliv3.CreateFoo workflow, starting it if necessary, and blocks until update completion
	CreateFooWithUpdateFoo(ctx context.Context, req *CreateFooInput, update *UpdateFooInput, opts ...*CreateFooWithUpdateFooOptions) (*UpdateFooOutput, CreateFooRun, error)
	// CreateFooWithUpdateFooAsync starts a(n) test.cliv3.UpdateFoo update on a(n) test.cliv3.CreateFoo workflow, starting it if necessary, and returns a handle to the update execution
	CreateFooWithUpdateFooAsync(ctx context.Context, req *CreateFooInput, update *UpdateFooInput, opts ...*CreateFooWithUpdateFooOptions) (UpdateFooHandle, CreateFooRun, error)
	// 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

	// test.cliv3.ExampleService.GetFoo executes a(n) test.cliv3.GetFoo query
	GetFoo(ctx context.Context, workflowID string, runID string, query *GetFooInput) (*GetFooOutput, error)

	// test.cliv3.ExampleService.SignalFoo sends a(n) test.cliv3.SignalFoo signal
	SignalFoo(ctx context.Context, workflowID string, runID string, signal *SignalFooInput) error

	// UpdateFoo executes a(n) test.cliv3.UpdateFoo update and blocks until update completion
	UpdateFoo(ctx context.Context, workflowID string, runID string, req *UpdateFooInput, opts ...*UpdateFooOptions) (*UpdateFooOutput, error)

	// UpdateFooAsync starts a(n) test.cliv3.UpdateFoo update and returns a handle to the workflow update
	UpdateFooAsync(ctx context.Context, workflowID string, runID string, req *UpdateFooInput, opts ...*UpdateFooOptions) (UpdateFooHandle, error)

	// GetUpdateFoo retrieves a handle to an existing test.cliv3.UpdateFoo update
	GetUpdateFoo(ctx context.Context, req client.GetWorkflowUpdateHandleOptions) (UpdateFooHandle, error)
}

// exampleServiceClient implements a temporal client for a test.cliv3.ExampleService service
type exampleServiceClient struct {
	client client.Client
	log    *slog.Logger
}

// NewExampleServiceClient initializes a new test.cliv3.ExampleService client
func NewExampleServiceClient(c client.Client, options ...*exampleServiceClientOptions) ExampleServiceClient {
	var cfg *exampleServiceClientOptions
	if len(options) > 0 {
		cfg = options[0]
	} else {
		cfg = NewExampleServiceClientOptions()
	}
	return &exampleServiceClient{
		client: c,
		log:    cfg.getLogger(),
	}
}

// NewExampleServiceClientWithOptions initializes a new ExampleService client with the given options
func NewExampleServiceClientWithOptions(c client.Client, opts client.Options, options ...*exampleServiceClientOptions) (ExampleServiceClient, 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 *exampleServiceClientOptions
	if len(options) > 0 {
		cfg = options[0]
	} else {
		cfg = NewExampleServiceClientOptions()
	}
	return &exampleServiceClient{
		client: c,
		log:    cfg.getLogger(),
	}, nil
}

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

// NewExampleServiceClientOptions initializes a new exampleServiceClientOptions value
func NewExampleServiceClientOptions() *exampleServiceClientOptions {
	return &exampleServiceClientOptions{}
}

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

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

// test.cliv3.ExampleService.CreateFoo executes a test.cliv3.CreateFoo workflow and blocks until error or response received
func (c *exampleServiceClient) CreateFoo(ctx context.Context, req *CreateFooInput, options ...*CreateFooOptions) (*CreateFooOutput, error) {
	run, err := c.CreateFooAsync(ctx, req, options...)
	if err != nil {
		return nil, err
	}
	return run.Get(ctx)
}

// CreateFooAsync starts a(n) test.cliv3.CreateFoo workflow and returns a handle to the workflow run
func (c *exampleServiceClient) CreateFooAsync(ctx context.Context, req *CreateFooInput, options ...*CreateFooOptions) (CreateFooRun, error) {
	var o *CreateFooOptions
	if len(options) > 0 && options[0] != nil {
		o = options[0]
	} else {
		o = NewCreateFooOptions()
	}
	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, CreateFooWorkflowName, req)
	if err != nil {
		return nil, err
	}
	if run == nil {
		return nil, errors.New("execute workflow returned nil run")
	}
	return &createFooRun{
		client: c,
		run:    run,
	}, nil
}

// GetCreateFoo fetches an existing test.cliv3.CreateFoo execution
func (c *exampleServiceClient) GetCreateFoo(ctx context.Context, workflowID string, runID string) CreateFooRun {
	return &createFooRun{
		client: c,
		run:    c.client.GetWorkflow(ctx, workflowID, runID),
	}
}

// CreateFooWithSignalFoo starts a(n) test.cliv3.CreateFoo workflow and sends a(n) test.cliv3.SignalFoo signal in a transaction
func (c *exampleServiceClient) CreateFooWithSignalFoo(ctx context.Context, req *CreateFooInput, signal *SignalFooInput, options ...*CreateFooOptions) (*CreateFooOutput, error) {
	run, err := c.CreateFooWithSignalFooAsync(ctx, req, signal, options...)
	if err != nil {
		return nil, err
	}
	return run.Get(ctx)
}

// CreateFooWithSignalFooAsync starts a(n) test.cliv3.CreateFoo workflow and sends a(n) test.cliv3.SignalFoo signal in a transaction
func (c *exampleServiceClient) CreateFooWithSignalFooAsync(ctx context.Context, req *CreateFooInput, signal *SignalFooInput, options ...*CreateFooOptions) (CreateFooRun, error) {
	var o *CreateFooOptions
	if len(options) > 0 && options[0] != nil {
		o = options[0]
	} else {
		o = NewCreateFooOptions()
	}
	opts, err := o.Build(req.ProtoReflect())
	if err != nil {
		return nil, fmt.Errorf("error initializing client.StartWorkflowOptions: %w", err)
	}
	run, err := c.client.SignalWithStartWorkflow(ctx, opts.ID, SignalFooSignalName, signal, opts, CreateFooWorkflowName, req)
	if run == nil || err != nil {
		return nil, err
	}
	return &createFooRun{
		client: c,
		run:    run,
	}, nil
}

// CreateFooWithUpdateFooOptions is the options for a test.cliv3.CreateFoo workflow with a test.cliv3.UpdateFoo update
type CreateFooWithUpdateFooOptions struct {
	options         client.UpdateWithStartWorkflowOptions
	workflowOptions *CreateFooOptions
	updateOptions   *UpdateFooOptions
}

// NewCreateFooWithUpdateFooOptions initializes a new CreateFooWithUpdateFooOptions value
func NewCreateFooWithUpdateFooOptions() *CreateFooWithUpdateFooOptions {
	return &CreateFooWithUpdateFooOptions{}
}

// Build transforms CreateFooWithUpdateFooOptions into valid client.UpdateWithStartWorkflowOptions
func (o *CreateFooWithUpdateFooOptions) Build(ctx context.Context, op func(client.StartWorkflowOptions) client.WithStartWorkflowOperation, input *CreateFooInput, update *UpdateFooInput) (options client.UpdateWithStartWorkflowOptions, err error) {
	options = o.options
	if o.workflowOptions == nil {
		o.workflowOptions = NewCreateFooOptions()
	}
	swo, err := o.workflowOptions.Build(input.ProtoReflect())
	if err != nil {
		return options, err
	}
	if swo.WorkflowIDConflictPolicy == enumsv1.WORKFLOW_ID_CONFLICT_POLICY_UNSPECIFIED {
		swo.WorkflowIDConflictPolicy = enumsv1.WORKFLOW_ID_CONFLICT_POLICY_FAIL
	}
	options.StartWorkflowOperation = op(swo)
	if o.updateOptions == nil {
		o.updateOptions = NewUpdateFooOptions()
	}
	uo, err := o.updateOptions.Build(swo.ID, "", update)
	if err != nil {
		return options, err
	}
	options.UpdateOptions = *uo
	return options, nil
}

// WithUpdateWithStartWorkflowOptions sets the UpdateWithStartWorkflowOptions
func (o *CreateFooWithUpdateFooOptions) WithUpdateWithStartWorkflowOptions(options client.UpdateWithStartWorkflowOptions) *CreateFooWithUpdateFooOptions {
	o.options = options
	return o
}

// WithCreateFooOptions sets the WithCreateFooOptions
func (o *CreateFooWithUpdateFooOptions) WithCreateFooOptions(options *CreateFooOptions) *CreateFooWithUpdateFooOptions {
	o.workflowOptions = options
	return o
}

// WithUpdateFooOptions sets the UpdateFooOptions
func (o *CreateFooWithUpdateFooOptions) WithUpdateFooOptions(options *UpdateFooOptions) *CreateFooWithUpdateFooOptions {
	o.updateOptions = options
	return o
}

// CreateFooWithUpdateFoo starts a(n) test.cliv3.CreateFoo workflow and executes a(n) test.cliv3.UpdateFoo update in a transaction
func (c *exampleServiceClient) CreateFooWithUpdateFoo(ctx context.Context, req *CreateFooInput, update *UpdateFooInput, options ...*CreateFooWithUpdateFooOptions) (*UpdateFooOutput, CreateFooRun, error) {
	updateHandle, run, err := c.CreateFooWithUpdateFooAsync(ctx, req, update, options...)
	if err != nil {
		return nil, run, err
	}
	out, err := updateHandle.Get(ctx)
	if err != nil {
		return nil, run, err
	}
	return out, run, nil
}

// CreateFooWithUpdateFooAsync starts a(n) test.cliv3.CreateFoo workflow and executes a(n) test.cliv3.UpdateFoo update in a transaction
func (c *exampleServiceClient) CreateFooWithUpdateFooAsync(ctx context.Context, req *CreateFooInput, update *UpdateFooInput, options ...*CreateFooWithUpdateFooOptions) (UpdateFooHandle, CreateFooRun, error) {
	var o *CreateFooWithUpdateFooOptions
	if len(options) > 0 && options[0] != nil {
		o = options[0]
	} else {
		o = NewCreateFooWithUpdateFooOptions()
	}
	opts, err := o.Build(ctx, func(swo client.StartWorkflowOptions) client.WithStartWorkflowOperation {
		return c.client.NewWithStartWorkflowOperation(swo, CreateFooWorkflowName, req)
	}, req, update)
	if err != nil {
		return nil, nil, fmt.Errorf("error initializing UpdateWorkflowWithOptions: %w", err)
	}
	handle, err := c.client.UpdateWithStartWorkflow(ctx, opts)
	if err != nil {
		return nil, nil, err
	}
	return &updateFooHandle{
		client: c,
		handle: handle,
	}, c.GetCreateFoo(ctx, handle.WorkflowID(), handle.RunID()), nil
}

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

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

// test.cliv3.ExampleService.GetFoo sends a(n) test.cliv3.GetFoo query to an existing workflow
func (c *exampleServiceClient) GetFoo(ctx context.Context, workflowID string, runID string, query *GetFooInput) (*GetFooOutput, error) {
	var resp GetFooOutput
	if val, err := c.client.QueryWorkflow(ctx, workflowID, runID, GetFooQueryName, query); err != nil {
		return nil, err
	} else if err = val.Get(&resp); err != nil {
		return nil, err
	}
	return &resp, nil
}

// test.cliv3.ExampleService.SignalFoo sends a(n) test.cliv3.SignalFoo signal to an existing workflow
func (c *exampleServiceClient) SignalFoo(ctx context.Context, workflowID string, runID string, signal *SignalFooInput) error {
	return c.client.SignalWorkflow(ctx, workflowID, runID, SignalFooSignalName, signal)
}

// test.cliv3.ExampleService.UpdateFoo sends a(n) test.cliv3.UpdateFoo update to an existing workflow
func (c *exampleServiceClient) UpdateFoo(ctx context.Context, workflowID string, runID string, req *UpdateFooInput, opts ...*UpdateFooOptions) (*UpdateFooOutput, error) {
	// initialize update options
	o := NewUpdateFooOptions()
	if len(opts) > 0 && opts[0].Options != nil {
		o = opts[0]
	}

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

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

// test.cliv3.ExampleService.UpdateFoo sends a(n) test.cliv3.UpdateFoo update to an existing workflow
func (c *exampleServiceClient) UpdateFooAsync(ctx context.Context, workflowID string, runID string, req *UpdateFooInput, opts ...*UpdateFooOptions) (UpdateFooHandle, error) {
	// initialize update options
	var o *UpdateFooOptions
	if len(opts) > 0 && opts[0] != nil {
		o = opts[0]
	} else {
		o = NewUpdateFooOptions()
	}

	// 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 &updateFooHandle{client: c, handle: handle}, nil
}

// GetUpdateFoo retrieves a handle to an existing test.cliv3.UpdateFoo update
func (c *exampleServiceClient) GetUpdateFoo(ctx context.Context, req client.GetWorkflowUpdateHandleOptions) (UpdateFooHandle, error) {
	return &updateFooHandle{
		client: c,
		handle: c.client.GetWorkflowUpdateHandle(req),
	}, nil
}

// CreateFooOptions provides configuration for a test.cliv3.CreateFoo workflow operation
type CreateFooOptions 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
}

// NewCreateFooOptions initializes a new CreateFooOptions value
func NewCreateFooOptions() *CreateFooOptions {
	return &CreateFooOptions{}
}

// Build initializes a new go.temporal.io/sdk/client.StartWorkflowOptions value with defaults and overrides applied
func (o *CreateFooOptions) Build(req protoreflect.Message) (client.StartWorkflowOptions, error) {
	opts := o.options
	if v := o.id; v != nil {
		opts.ID = *v
	}
	if v := o.idReusePolicy; v != enumsv1.WORKFLOW_ID_REUSE_POLICY_UNSPECIFIED {
		opts.WorkflowIDReusePolicy = v
	}
	if v := o.workflowIdConflictPolicy; v != enumsv1.WORKFLOW_ID_CONFLICT_POLICY_UNSPECIFIED {
		opts.WorkflowIDConflictPolicy = v
	}
	if v := o.taskQueue; v != nil {
		opts.TaskQueue = *v
	} else if opts.TaskQueue == "" {
		opts.TaskQueue = ExampleServiceTaskQueue
	}
	if v := o.retryPolicy; v != nil {
		opts.RetryPolicy = v
	}
	if v := o.searchAttributes; v != nil {
		opts.SearchAttributes = o.searchAttributes
	}
	if v := o.executionTimeout; v != nil {
		opts.WorkflowExecutionTimeout = *v
	}
	if v := o.runTimeout; v != nil {
		opts.WorkflowRunTimeout = *v
	}
	if v := o.taskTimeout; v != nil {
		opts.WorkflowTaskTimeout = *v
	}
	return opts, nil
}

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

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

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

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

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

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

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

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

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

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

// CreateFooRun describes a(n) test.cliv3.CreateFoo workflow run
type CreateFooRun 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) (*CreateFooOutput, 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.cliv3.ExampleService.GetFoo executes a(n) test.cliv3.GetFoo query
	GetFoo(ctx context.Context, req *GetFooInput) (*GetFooOutput, error)

	// test.cliv3.ExampleService.SignalFoo sends a(n) test.cliv3.SignalFoo signal
	SignalFoo(ctx context.Context, req *SignalFooInput) error

	// test.cliv3.ExampleService.UpdateFoo executes a(n) test.cliv3.UpdateFoo update
	UpdateFoo(ctx context.Context, req *UpdateFooInput, opts ...*UpdateFooOptions) (*UpdateFooOutput, error)

	// test.cliv3.ExampleService.UpdateFooAsync sends a(n) test.cliv3.UpdateFoo update to the workflow
	UpdateFooAsync(ctx context.Context, req *UpdateFooInput, opts ...*UpdateFooOptions) (UpdateFooHandle, error)
}

// createFooRun provides an internal implementation of a(n) CreateFooRunRun
type createFooRun struct {
	client *exampleServiceClient
	run    client.WorkflowRun
}

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

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

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

// Cancel requests cancellation of a workflow in execution, returning an error if applicable
func (r *createFooRun) 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 *createFooRun) Get(ctx context.Context) (*CreateFooOutput, error) {
	var resp CreateFooOutput
	if err := r.run.Get(ctx, &resp); err != nil {
		return nil, err
	}
	return &resp, nil
}

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

// test.cliv3.ExampleService.GetFoo executes a(n) test.cliv3.GetFoo query
func (r *createFooRun) GetFoo(ctx context.Context, req *GetFooInput) (*GetFooOutput, error) {
	return r.client.GetFoo(ctx, r.ID(), "", req)
}

// test.cliv3.ExampleService.SignalFoo sends a(n) test.cliv3.SignalFoo signal
func (r *createFooRun) SignalFoo(ctx context.Context, req *SignalFooInput) error {
	return r.client.SignalFoo(ctx, r.ID(), "", req)
}

// test.cliv3.ExampleService.UpdateFoo executes a(n) test.cliv3.UpdateFoo workflow update
func (r *createFooRun) UpdateFoo(ctx context.Context, req *UpdateFooInput, opts ...*UpdateFooOptions) (*UpdateFooOutput, error) {
	return r.client.UpdateFoo(ctx, r.ID(), r.RunID(), req, opts...)
}

// UpdateFooAsync start a(n) test.cliv3.UpdateFoo workflow update and returns a handle to the update
func (r *createFooRun) UpdateFooAsync(ctx context.Context, req *UpdateFooInput, opts ...*UpdateFooOptions) (UpdateFooHandle, error) {
	return r.client.UpdateFooAsync(ctx, r.ID(), r.RunID(), req, opts...)
}

// UpdateFooHandle describes a(n) test.cliv3.UpdateFoo update handle
type UpdateFooHandle 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) (*UpdateFooOutput, error)
}

// updateFooHandle provides an internal implementation of a(n) UpdateFooHandle
type updateFooHandle struct {
	client *exampleServiceClient
	handle client.WorkflowUpdateHandle
}

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

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

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

// Get blocks until the update wait policy is met, returning the result if applicable
func (h *updateFooHandle) Get(ctx context.Context) (*UpdateFooOutput, error) {
	var resp UpdateFooOutput
	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, &resp); 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 nil, ctx.Err()
	case <-doneCh:
		if err != nil {
			return nil, err
		}
		return &resp, nil
	}
}

// UpdateFooOptions provides configuration for a test.cliv3.UpdateFoo update operation
type UpdateFooOptions struct {
	Options    *client.UpdateWorkflowOptions
	id         *string
	waitPolicy client.WorkflowUpdateStage
}

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

// Build initializes a new client.UpdateWorkflowOptions with defaults and overrides applied
func (o *UpdateFooOptions) Build(workflowID string, runID string, req *UpdateFooInput) (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 = UpdateFooUpdateName
	opts.WorkflowID = workflowID

	// set UpdateID
	if v := o.id; v != nil {
		opts.UpdateID = *v
	}

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

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

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

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

// Reference to generated workflow functions
var (
	// exampleServiceRegistrationMutex is a mutex for registering test.cliv3.ExampleService workflows
	exampleServiceRegistrationMutex sync.Mutex
	// CreateFooFunction implements a "test.cliv3.CreateFoo" workflow
	CreateFooFunction func(workflow.Context, *CreateFooInput) (*CreateFooOutput, error)
)

// ExampleServiceWorkflowFunctions describes a mockable dependency for inlining workflows within other workflows
type (
	// ExampleServiceWorkflowFunctions describes a mockable dependency for inlining workflows within other workflows
	ExampleServiceWorkflowFunctions interface {
		// CreateFoo executes a "test.cliv3.CreateFoo" workflow inline
		CreateFoo(workflow.Context, *CreateFooInput) (*CreateFooOutput, error)
	}
	// exampleServiceWorkflowFunctions provides an internal ExampleServiceWorkflowFunctions implementation
	exampleServiceWorkflowFunctions struct{}
)

func NewExampleServiceWorkflowFunctions() ExampleServiceWorkflowFunctions {
	return &exampleServiceWorkflowFunctions{}
}

// CreateFoo executes a "test.cliv3.CreateFoo" workflow inline
func (f *exampleServiceWorkflowFunctions) CreateFoo(ctx workflow.Context, req *CreateFooInput) (*CreateFooOutput, error) {
	if CreateFooFunction == nil {
		return nil, errors.New("CreateFoo requires workflow registration via RegisterExampleServiceWorkflows or RegisterCreateFooWorkflow")
	}
	return CreateFooFunction(ctx, req)
}

// ExampleServiceWorkflows provides methods for initializing new test.cliv3.ExampleService workflow values
type ExampleServiceWorkflows interface {
	// CreateFoo initializes a new a(n) CreateFooWorkflow implementation
	CreateFoo(ctx workflow.Context, input *CreateFooWorkflowInput) (CreateFooWorkflow, error)
}

// RegisterExampleServiceWorkflows registers test.cliv3.ExampleService workflows with the given worker
func RegisterExampleServiceWorkflows(r worker.WorkflowRegistry, workflows ExampleServiceWorkflows) {
	RegisterCreateFooWorkflow(r, workflows.CreateFoo)
}

// RegisterCreateFooWorkflow registers a test.cliv3.ExampleService.CreateFoo workflow with the given worker
func RegisterCreateFooWorkflow(r worker.WorkflowRegistry, wf func(workflow.Context, *CreateFooWorkflowInput) (CreateFooWorkflow, error)) {
	exampleServiceRegistrationMutex.Lock()
	defer exampleServiceRegistrationMutex.Unlock()
	CreateFooFunction = buildCreateFoo(wf)
	r.RegisterWorkflowWithOptions(CreateFooFunction, workflow.RegisterOptions{Name: CreateFooWorkflowName})
}

// buildCreateFoo converts a CreateFoo workflow struct into a valid workflow function
func buildCreateFoo(ctor func(workflow.Context, *CreateFooWorkflowInput) (CreateFooWorkflow, error)) func(workflow.Context, *CreateFooInput) (*CreateFooOutput, error) {
	return func(ctx workflow.Context, req *CreateFooInput) (*CreateFooOutput, error) {
		input := &CreateFooWorkflowInput{
			Req: req,
			SignalFoo: &SignalFooSignal{
				Channel: workflow.GetSignalChannel(ctx, SignalFooSignalName),
			},
		}
		wf, err := ctor(ctx, input)
		if err != nil {
			return nil, err
		}
		if initializable, ok := wf.(helpers.Initializable); ok {
			if err := initializable.Initialize(ctx); err != nil {
				return nil, err
			}
		}
		if err := workflow.SetQueryHandler(ctx, GetFooQueryName, wf.GetFoo); err != nil {
			return nil, err
		}
		{
			opts := workflow.UpdateHandlerOptions{Validator: wf.ValidateUpdateFoo}
			if err := workflow.SetUpdateHandlerWithOptions(ctx, UpdateFooUpdateName, wf.UpdateFoo, opts); err != nil {
				return nil, err
			}
		}
		return wf.Execute(ctx)
	}
}

// CreateFooWorkflowInput describes the input to a(n) test.cliv3.CreateFoo workflow constructor
type CreateFooWorkflowInput struct {
	Req       *CreateFooInput
	SignalFoo *SignalFooSignal
}

// CreateFooWorkflow describes a(n) test.cliv3.CreateFoo workflow implementation
type CreateFooWorkflow interface {
	// Execute defines the entrypoint to a(n) test.cliv3.CreateFoo workflow
	Execute(ctx workflow.Context) (*CreateFooOutput, error)

	// test.cliv3.ExampleService.GetFoo implements a(n) test.cliv3.GetFoo query handler
	GetFoo(*GetFooInput) (*GetFooOutput, error)

	// ValidateUpdateFoo validates a(n) test.cliv3.UpdateFoo update
	ValidateUpdateFoo(workflow.Context, *UpdateFooInput) error

	// test.cliv3.ExampleService.UpdateFoo implements a(n) test.cliv3.ExampleService.UpdateFoo update handler
	UpdateFoo(workflow.Context, *UpdateFooInput) (*UpdateFooOutput, error)
}

// CreateFooChild executes a child test.cliv3.CreateFoo workflow and blocks until error or response received
func CreateFooChild(ctx workflow.Context, req *CreateFooInput, options ...*CreateFooChildOptions) (*CreateFooOutput, error) {
	childRun, err := CreateFooChildAsync(ctx, req, options...)
	if err != nil {
		return nil, err
	}
	return childRun.Get(ctx)
}

// CreateFooChildAsync starts a child test.cliv3.CreateFoo workflow and returns a handle to the child workflow run
func CreateFooChildAsync(ctx workflow.Context, req *CreateFooInput, options ...*CreateFooChildOptions) (*CreateFooChildRun, error) {
	var o *CreateFooChildOptions
	if len(options) > 0 && options[0] != nil {
		o = options[0]
	} else {
		o = NewCreateFooChildOptions()
	}
	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 &CreateFooChildRun{Future: workflow.ExecuteChildWorkflow(ctx, CreateFooWorkflowName, req)}, nil
}

// CreateFooChildOptions provides configuration for a child test.cliv3.CreateFoo workflow operation
type CreateFooChildOptions 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
}

// NewCreateFooChildOptions initializes a new CreateFooChildOptions value
func NewCreateFooChildOptions() *CreateFooChildOptions {
	return &CreateFooChildOptions{}
}

// Build initializes a new go.temporal.io/sdk/workflow.ChildWorkflowOptions value with defaults and overrides applied
func (o *CreateFooChildOptions) Build(ctx workflow.Context, req protoreflect.Message) (workflow.ChildWorkflowOptions, error) {
	opts := o.options
	if v := o.id; v != nil {
		opts.WorkflowID = *v
	}
	if v := o.idReusePolicy; v != enumsv1.WORKFLOW_ID_REUSE_POLICY_UNSPECIFIED {
		opts.WorkflowIDReusePolicy = v
	}
	if v := o.taskQueue; v != nil {
		opts.TaskQueue = *v
	} else if opts.TaskQueue == "" {
		opts.TaskQueue = ExampleServiceTaskQueue
	}
	if v := o.retryPolicy; v != nil {
		opts.RetryPolicy = v
	}
	if v := o.searchAttributes; v != nil {
		opts.SearchAttributes = o.searchAttributes
	}
	if v := o.executionTimeout; v != nil {
		opts.WorkflowExecutionTimeout = *v
	}
	if v := o.runTimeout; v != nil {
		opts.WorkflowRunTimeout = *v
	}
	if v := o.taskTimeout; v != nil {
		opts.WorkflowTaskTimeout = *v
	}
	if v := o.parentClosePolicy; v != enumsv1.PARENT_CLOSE_POLICY_UNSPECIFIED {
		opts.ParentClosePolicy = v
	}
	if v := o.waitForCancellation; v != nil {
		opts.WaitForCancellation = *v
	}
	return opts, nil
}

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

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

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

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

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

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

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

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

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

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

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

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

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

// CreateFooChildRun describes a child CreateFoo workflow run
type CreateFooChildRun struct {
	Future workflow.ChildWorkflowFuture
}

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

// Select adds this completion to the selector. Callback can be nil.
func (r *CreateFooChildRun) Select(sel workflow.Selector, fn func(*CreateFooChildRun)) 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 *CreateFooChildRun) SelectStart(sel workflow.Selector, fn func(*CreateFooChildRun)) 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 *CreateFooChildRun) 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
}

// SignalFoo sends a(n) "test.cliv3.SignalFoo" signal request to the child workflow
func (r *CreateFooChildRun) SignalFoo(ctx workflow.Context, input *SignalFooInput) error {
	return r.SignalFooAsync(ctx, input).Get(ctx, nil)
}

// SignalFooAsync sends a(n) "test.cliv3.SignalFoo" signal request to the child workflow
func (r *CreateFooChildRun) SignalFooAsync(ctx workflow.Context, input *SignalFooInput) workflow.Future {
	return r.Future.SignalChildWorkflow(ctx, SignalFooSignalName, input)
}

// SignalFooSignal describes a(n) test.cliv3.ExampleService.SignalFoo signal
type SignalFooSignal struct {
	Channel workflow.ReceiveChannel
}

// NewSignalFooSignal initializes a new test.cliv3.SignalFoo signal wrapper
func NewSignalFooSignal(ctx workflow.Context) *SignalFooSignal {
	return &SignalFooSignal{Channel: workflow.GetSignalChannel(ctx, SignalFooSignalName)}
}

// Receive blocks until a(n) test.cliv3.ExampleService.SignalFoo signal is received
func (s *SignalFooSignal) Receive(ctx workflow.Context) (*SignalFooInput, bool) {
	var resp SignalFooInput
	more := s.Channel.Receive(ctx, &resp)
	return &resp, more
}

// ReceiveAsync checks for a test.cliv3.ExampleService.SignalFoo signal without blocking
func (s *SignalFooSignal) ReceiveAsync() *SignalFooInput {
	var resp SignalFooInput
	if ok := s.Channel.ReceiveAsync(&resp); !ok {
		return nil
	}
	return &resp
}

// ReceiveWithTimeout blocks until a(n) test.cliv3.ExampleService.SignalFoo signal is received or timeout expires.
// Returns more value of false when Channel is closed.
// Returns ok value of false when no value was found in the channel for the duration of timeout or the ctx was canceled.
// resp will be nil if ok is false.
func (s *SignalFooSignal) ReceiveWithTimeout(ctx workflow.Context, timeout time.Duration) (resp *SignalFooInput, ok bool, more bool) {
	resp = &SignalFooInput{}
	if ok, more = s.Channel.ReceiveWithTimeout(ctx, timeout, &resp); !ok {
		return nil, false, more
	}
	return
}

// Select checks for a(n) test.cliv3.ExampleService.SignalFoo signal without blocking
func (s *SignalFooSignal) Select(sel workflow.Selector, fn func(*SignalFooInput)) workflow.Selector {
	return sel.AddReceive(s.Channel, func(workflow.ReceiveChannel, bool) {
		req := s.ReceiveAsync()
		if fn != nil {
			fn(req)
		}
	})
}

// SignalFooExternal sends a(n) test.cliv3.SignalFoo signal to an existing workflow
func SignalFooExternal(ctx workflow.Context, workflowID string, runID string, req *SignalFooInput) error {
	return SignalFooExternalAsync(ctx, workflowID, runID, req).Get(ctx, nil)
}

// SignalFooExternalAsync sends a(n) test.cliv3.SignalFoo signal to an existing workflow
func SignalFooExternalAsync(ctx workflow.Context, workflowID string, runID string, req *SignalFooInput) workflow.Future {
	return workflow.SignalExternalWorkflow(ctx, workflowID, runID, SignalFooSignalName, req)
}

// ExampleServiceActivities describes available worker activities
type ExampleServiceActivities interface{}

// RegisterExampleServiceActivities registers activities with a worker
func RegisterExampleServiceActivities(r worker.ActivityRegistry, activities ExampleServiceActivities) {
}

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

var _ ExampleServiceClient = &TestExampleServiceClient{}

// NewTestExampleServiceClient initializes a new TestExampleServiceClient value
func NewTestExampleServiceClient(env *testsuite.TestWorkflowEnvironment, workflows ExampleServiceWorkflows, activities ExampleServiceActivities) *TestExampleServiceClient {
	if workflows != nil {
		RegisterExampleServiceWorkflows(env, workflows)
	}
	if activities != nil {
		RegisterExampleServiceActivities(env, activities)
	}
	return &TestExampleServiceClient{env, workflows}
}

// CreateFoo executes a(n) test.cliv3.CreateFoo workflow in the test environment
func (c *TestExampleServiceClient) CreateFoo(ctx context.Context, req *CreateFooInput, opts ...*CreateFooOptions) (*CreateFooOutput, error) {
	run, err := c.CreateFooAsync(ctx, req, opts...)
	if err != nil {
		return nil, err
	}
	return run.Get(ctx)
}

// CreateFooAsync executes a(n) test.cliv3.CreateFoo workflow in the test environment
func (c *TestExampleServiceClient) CreateFooAsync(ctx context.Context, req *CreateFooInput, options ...*CreateFooOptions) (CreateFooRun, error) {
	var o *CreateFooOptions
	if len(options) > 0 && options[0] != nil {
		o = options[0]
	} else {
		o = NewCreateFooOptions()
	}
	opts, err := o.Build(req.ProtoReflect())
	if err != nil {
		return nil, fmt.Errorf("error initializing client.StartWorkflowOptions: %w", err)
	}
	return &testCreateFooRun{client: c, env: c.env, opts: &opts, req: req, workflows: c.workflows}, nil
}

// GetCreateFoo is a noop
func (c *TestExampleServiceClient) GetCreateFoo(ctx context.Context, workflowID string, runID string) CreateFooRun {
	return &testCreateFooRun{env: c.env, workflows: c.workflows}
}

// CreateFooWithSignalFoo sends a(n) test.cliv3.SignalFoo signal to a(n) test.cliv3.CreateFoo workflow, starting it if necessary
func (c *TestExampleServiceClient) CreateFooWithSignalFoo(ctx context.Context, req *CreateFooInput, signal *SignalFooInput, opts ...*CreateFooOptions) (*CreateFooOutput, error) {
	c.env.RegisterDelayedCallback(func() {
		c.env.SignalWorkflow(SignalFooSignalName, signal)
	}, 0)
	return c.CreateFoo(ctx, req, opts...)
}

// CreateFooWithSignalFooAsync sends a(n) test.cliv3.SignalFoo signal to a(n) test.cliv3.CreateFoo workflow, starting it if necessary
func (c *TestExampleServiceClient) CreateFooWithSignalFooAsync(ctx context.Context, req *CreateFooInput, signal *SignalFooInput, opts ...*CreateFooOptions) (CreateFooRun, error) {
	c.env.RegisterDelayedCallback(func() {
		c.env.SignalWorkflow(SignalFooSignalName, signal)
	}, 0)
	return c.CreateFooAsync(ctx, req, opts...)
}

// CreateFooWithUpdateFoo executes a(n) test.cliv3.CreateFoo workflow and a(n) test.cliv3.UpdateFoo update in the test environment
func (c *TestExampleServiceClient) CreateFooWithUpdateFoo(ctx context.Context, input *CreateFooInput, update *UpdateFooInput, options ...*CreateFooWithUpdateFooOptions) (*UpdateFooOutput, CreateFooRun, error) {
	var o *CreateFooWithUpdateFooOptions
	if len(options) > 0 && options[0] != nil {
		o = options[0]
	} else {
		o = NewCreateFooWithUpdateFooOptions()
	}
	handle, run, err := c.CreateFooWithUpdateFooAsync(ctx, input, update, o)
	if err != nil {
		return nil, run, err
	}
	run.Get(ctx)
	out, err := handle.Get(ctx)
	if err != nil {
		return nil, run, err
	}
	return out, run, nil
}

// CreateFooWithUpdateFooAsync executes a(n) test.cliv3.CreateFoo workflow and a(n) test.cliv3.UpdateFoo update in the test environment
func (c *TestExampleServiceClient) CreateFooWithUpdateFooAsync(ctx context.Context, input *CreateFooInput, update *UpdateFooInput, options ...*CreateFooWithUpdateFooOptions) (UpdateFooHandle, CreateFooRun, error) {
	var o *CreateFooWithUpdateFooOptions
	if len(options) > 0 && options[0] != nil {
		o = options[0]
	} else {
		o = NewCreateFooWithUpdateFooOptions()
	}
	if o.workflowOptions == nil {
		o.workflowOptions = NewCreateFooOptions()
	}
	swo, err := o.workflowOptions.Build(input.ProtoReflect())
	if err != nil {
		return nil, nil, fmt.Errorf("error initializing workflowOptions: %w", err)
	}
	if o.updateOptions == nil {
		o.updateOptions = NewUpdateFooOptions()
	}
	uo, err := o.updateOptions.Build(swo.ID, "", update)
	if err != nil {
		return nil, nil, fmt.Errorf("error initializing updateOptions: %w", err)
	}
	run, err := c.CreateFooAsync(ctx, input)
	if err != nil {
		return nil, nil, err
	}
	uc := testutil.NewUpdateCallbacks()
	c.env.RegisterDelayedCallback(func() {
		c.env.UpdateWorkflow(UpdateFooUpdateName, uo.UpdateID, uc, update)
	}, 0)
	return &testUpdateFooHandle{
		callbacks:  uc,
		env:        c.env,
		opts:       uo,
		req:        update,
		runID:      "",
		workflowID: swo.ID,
	}, run, nil
}

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

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

// GetFoo executes a test.cliv3.GetFoo query
func (c *TestExampleServiceClient) GetFoo(ctx context.Context, workflowID string, runID string, req *GetFooInput) (*GetFooOutput, error) {
	val, err := c.env.QueryWorkflow(GetFooQueryName, req)
	if err != nil {
		return nil, err
	} else if !val.HasValue() {
		return nil, nil
	} else {
		var result GetFooOutput
		if err := val.Get(&result); err != nil {
			return nil, err
		}
		return &result, nil
	}
}

// SignalFoo executes a test.cliv3.SignalFoo signal
func (c *TestExampleServiceClient) SignalFoo(ctx context.Context, workflowID string, runID string, req *SignalFooInput) error {
	c.env.SignalWorkflow(SignalFooSignalName, req)
	return nil
}

// UpdateFoo executes a(n) test.cliv3.UpdateFoo update in the test environment
func (c *TestExampleServiceClient) UpdateFoo(ctx context.Context, workflowID string, runID string, req *UpdateFooInput, opts ...*UpdateFooOptions) (*UpdateFooOutput, error) {
	options := NewUpdateFooOptions()
	if len(opts) > 0 && opts[0].Options != nil {
		options = opts[0]
	}
	options.Options.WaitForStage = client.WorkflowUpdateStageCompleted
	handle, err := c.UpdateFooAsync(ctx, workflowID, runID, req, options)
	if err != nil {
		return nil, err
	}
	return handle.Get(ctx)
}

// UpdateFooAsync executes a(n) test.cliv3.UpdateFoo update in the test environment
func (c *TestExampleServiceClient) UpdateFooAsync(ctx context.Context, workflowID string, runID string, req *UpdateFooInput, opts ...*UpdateFooOptions) (UpdateFooHandle, error) {
	var o *UpdateFooOptions
	if len(opts) > 0 && opts[0] != nil {
		o = opts[0]
	} else {
		o = NewUpdateFooOptions()
	}
	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(UpdateFooUpdateName, options.UpdateID, uc, req)
	return &testUpdateFooHandle{
		callbacks:  uc,
		env:        c.env,
		opts:       options,
		runID:      runID,
		workflowID: workflowID,
		req:        req,
	}, nil
}

// GetUpdateFoo retrieves a handle to an existing test.cliv3.UpdateFoo update
func (c *TestExampleServiceClient) GetUpdateFoo(ctx context.Context, req client.GetWorkflowUpdateHandleOptions) (UpdateFooHandle, error) {
	return nil, errors.New("unimplemented")
}

var _ UpdateFooHandle = &testUpdateFooHandle{}

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

// Get retrieves a test test.cliv3.UpdateFoo update result
func (h *testUpdateFooHandle) Get(ctx context.Context) (*UpdateFooOutput, error) {
	if resp, err := h.callbacks.Get(ctx); err != nil {
		return nil, err
	} else {
		return resp.(*UpdateFooOutput), nil
	}
}

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

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

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

var _ CreateFooRun = &testCreateFooRun{}

// testCreateFooRun provides convenience methods for interacting with a(n) test.cliv3.CreateFoo workflow in the test environment
type testCreateFooRun struct {
	client    *TestExampleServiceClient
	env       *testsuite.TestWorkflowEnvironment
	isStarted atomic.Bool
	opts      *client.StartWorkflowOptions
	req       *CreateFooInput
	workflows ExampleServiceWorkflows
}

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

// Get retrieves a test test.cliv3.CreateFoo workflow result
func (r *testCreateFooRun) Get(context.Context) (*CreateFooOutput, error) {
	if r.isStarted.CompareAndSwap(false, true) {
		r.env.ExecuteWorkflow(CreateFooWorkflowName, r.req)
	}
	if !r.env.IsWorkflowCompleted() {
		return nil, errors.New("workflow in progress")
	}
	if err := r.env.GetWorkflowError(); err != nil {
		return nil, err
	}
	var result CreateFooOutput
	if err := r.env.GetWorkflowResult(&result); err != nil {
		return nil, err
	}
	return &result, nil
}

// ID returns a test test.cliv3.CreateFoo workflow run's workflow ID
func (r *testCreateFooRun) ID() string {
	if r.opts != nil {
		return r.opts.ID
	}
	return ""
}

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

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

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

// GetFoo executes a test.cliv3.GetFoo query against a test test.cliv3.CreateFoo workflow
func (r *testCreateFooRun) GetFoo(ctx context.Context, req *GetFooInput) (*GetFooOutput, error) {
	return r.client.GetFoo(ctx, r.ID(), r.RunID(), req)
}

// SignalFoo executes a test.cliv3.SignalFoo signal against a test test.cliv3.CreateFoo workflow
func (r *testCreateFooRun) SignalFoo(ctx context.Context, req *SignalFooInput) error {
	return r.client.SignalFoo(ctx, r.ID(), r.RunID(), req)
}

// UpdateFoo executes a(n) test.cliv3.UpdateFoo update against a test test.cliv3.CreateFoo workflow
func (r *testCreateFooRun) UpdateFoo(ctx context.Context, req *UpdateFooInput, opts ...*UpdateFooOptions) (*UpdateFooOutput, error) {
	return r.client.UpdateFoo(ctx, r.ID(), r.RunID(), req, opts...)
}

// UpdateFooAsync executes a(n) test.cliv3.UpdateFoo update against a test test.cliv3.CreateFoo workflow
func (r *testCreateFooRun) UpdateFooAsync(ctx context.Context, req *UpdateFooInput, opts ...*UpdateFooOptions) (UpdateFooHandle, error) {
	return r.client.UpdateFooAsync(ctx, r.ID(), r.RunID(), req, opts...)
}

// ExampleServiceCliOptions describes runtime configuration for test.cliv3.ExampleService cli v3
type ExampleServiceCliOptions struct {
	after            func(context.Context, *cliv3.Command) error
	before           func(context.Context, *cliv3.Command) (context.Context, error)
	clientForCommand func(context.Context, *cliv3.Command) (client.Client, error)
	worker           func(context.Context, *cliv3.Command, client.Client) (worker.Worker, error)
}

// NewExampleServiceCliOptions initializes a new ExampleServiceCliOptions value
func NewExampleServiceCliOptions() *ExampleServiceCliOptions {
	return &ExampleServiceCliOptions{}
}

// WithAfter injects a custom After hook to be run after any command invocation
func (opts *ExampleServiceCliOptions) WithAfter(fn func(context.Context, *cliv3.Command) error) *ExampleServiceCliOptions {
	opts.after = fn
	return opts
}

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

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

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

// NewExampleServiceCli initializes a cli app for a(n) test.cliv3.ExampleService service
func NewExampleServiceCli(options ...*ExampleServiceCliOptions) (*cliv3.Command, error) {
	commands, err := newExampleServiceCommands(options...)
	if err != nil {
		return nil, fmt.Errorf("error initializing subcommands: %w", err)
	}
	return &cliv3.Command{
		Name:                      "example-service",
		Usage:                     "test.cliv3.ExampleService operations",
		Commands:                  commands,
		DisableSliceFlagSeparator: true,
	}, nil
}

// newExampleServiceCommands initializes (sub)commands for a test.cliv3.ExampleService cli or command
func newExampleServiceCommands(options ...*ExampleServiceCliOptions) ([]*cliv3.Command, error) {
	opts := &ExampleServiceCliOptions{}
	if len(options) > 0 {
		opts = options[0]
	}
	if opts.clientForCommand == nil {
		opts.clientForCommand = func(ctx context.Context, cmd *cliv3.Command) (client.Client, error) {
			return client.DialContext(ctx, client.Options{})
		}
	}
	commands := []*cliv3.Command{
		{
			Name:                   "get-foo",
			Usage:                  "executes a test.cliv3.GetFoo query and blocks until error or response received",
			Category:               "QUERIES",
			UseShortOptionHandling: true,
			Before:                 opts.before,
			After:                  opts.after,
			Flags: []cliv3.Flag{
				&cliv3.StringFlag{
					Name:     "workflow-id",
					Usage:    "workflow id",
					Required: true,
					Aliases:  []string{"w"},
				},
				&cliv3.StringFlag{
					Name:    "run-id",
					Usage:   "run id",
					Aliases: []string{"r"},
				},
				&cliv3.StringFlag{
					Name:     "input-file",
					Usage:    "path to json-formatted input file",
					Aliases:  []string{"f"},
					Category: "INPUT",
				},
			},
			Action: func(ctx context.Context, cmd *cliv3.Command) error {
				c, err := opts.clientForCommand(ctx, cmd)
				if err != nil {
					return fmt.Errorf("error initializing client for command: %w", err)
				}
				defer c.Close()
				client := NewExampleServiceClient(c)
				req, err := UnmarshalCliFlagsToGetFooInput(cmd, helpers.UnmarshalCliFlagsOptions{FromFile: "input-file"})
				if err != nil {
					return fmt.Errorf("error unmarshalling request: %w", err)
				}
				if resp, err := client.GetFoo(ctx, cmd.String("workflow-id"), cmd.String("run-id"), req); err != nil {
					return fmt.Errorf("error executing %q query: %w", GetFooQueryName, err)
				} else {
					b, err := protojson.Marshal(resp)
					if err != nil {
						return fmt.Errorf("error serializing response json: %w", err)
					}
					var out bytes.Buffer
					if err := json.Indent(&out, b, "", "  "); err != nil {
						return fmt.Errorf("error formatting json: %w", err)
					}
					fmt.Println(out.String())
					return nil
				}
			},
		},
		{
			Name:                   "signal-foo",
			Usage:                  "executes a test.cliv3.SignalFoo signal",
			Category:               "SIGNALS",
			UseShortOptionHandling: true,
			Before:                 opts.before,
			After:                  opts.after,
			Flags: []cliv3.Flag{
				&cliv3.StringFlag{
					Name:     "workflow-id",
					Usage:    "workflow id",
					Required: true,
					Aliases:  []string{"w"},
				},
				&cliv3.StringFlag{
					Name:    "run-id",
					Usage:   "run id",
					Aliases: []string{"r"},
				},
				&cliv3.StringFlag{
					Name:     "input-file",
					Usage:    "path to json-formatted input file",
					Aliases:  []string{"f"},
					Category: "INPUT",
				},
				&cliv3.Float64Flag{
					Name:     "progress",
					Usage:    "set the value of the operation's \"Progress\" parameter",
					Category: "INPUT",
				},
			},
			Action: func(ctx context.Context, cmd *cliv3.Command) error {
				c, err := opts.clientForCommand(ctx, cmd)
				if err != nil {
					return fmt.Errorf("error initializing client for command: %w", err)
				}
				defer c.Close()
				client := NewExampleServiceClient(c)
				req, err := UnmarshalCliFlagsToSignalFooInput(cmd, helpers.UnmarshalCliFlagsOptions{FromFile: "input-file"})
				if err != nil {
					return fmt.Errorf("error unmarshalling request: %w", err)
				}
				if err := client.SignalFoo(ctx, cmd.String("workflow-id"), cmd.String("run-id"), req); err != nil {
					return fmt.Errorf("error sending %q signal: %w", SignalFooSignalName, err)
				}
				fmt.Println("success")
				return nil
			},
		},
		{
			Name:                   "update-foo",
			Usage:                  "executes a(n) test.cliv3.UpdateFoo update",
			Category:               "UPDATES",
			UseShortOptionHandling: true,
			Before:                 opts.before,
			After:                  opts.after,
			Flags: []cliv3.Flag{
				&cliv3.BoolFlag{
					Name:    "detach",
					Usage:   "run workflow update in the background and print workflow, execution, and udpate id",
					Aliases: []string{"d"},
				},
				&cliv3.StringFlag{
					Name:     "workflow-id",
					Usage:    "workflow id",
					Required: true,
					Aliases:  []string{"w"},
				},
				&cliv3.StringFlag{
					Name:    "run-id",
					Usage:   "run id",
					Aliases: []string{"r"},
				},
				&cliv3.StringFlag{
					Name:     "input-file",
					Usage:    "path to json-formatted input file",
					Aliases:  []string{"f"},
					Category: "INPUT",
				},
				&cliv3.Float64Flag{
					Name:     "progress",
					Usage:    "set the value of the operation's \"Progress\" parameter",
					Category: "INPUT",
				},
			},
			Action: func(ctx context.Context, cmd *cliv3.Command) error {
				c, err := opts.clientForCommand(ctx, cmd)
				if err != nil {
					return fmt.Errorf("error initializing client for command: %w", err)
				}
				defer c.Close()
				client := NewExampleServiceClient(c)
				req, err := UnmarshalCliFlagsToUpdateFooInput(cmd, helpers.UnmarshalCliFlagsOptions{FromFile: "input-file"})
				if err != nil {
					return fmt.Errorf("error unmarshalling request: %w", err)
				}
				handle, err := client.UpdateFooAsync(ctx, cmd.String("workflow-id"), cmd.String("run-id"), req)
				if err != nil {
					return fmt.Errorf("error executing %s update: %w", UpdateFooUpdateName, 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 resp, err := handle.Get(ctx); err != nil {
					return err
				} else {
					b, err := protojson.Marshal(resp)
					if err != nil {
						return fmt.Errorf("error serializing response json: %w", err)
					}
					var out bytes.Buffer
					if err := json.Indent(&out, b, "", "  "); err != nil {
						return fmt.Errorf("error formatting json: %w", err)
					}
					fmt.Println(out.String())
					return nil
				}
			},
		},
		{
			Name:                   "create-foo",
			Usage:                  "executes a(n) test.cliv3.CreateFoo workflow",
			Category:               "WORKFLOWS",
			UseShortOptionHandling: true,
			Before:                 opts.before,
			After:                  opts.after,
			Flags: []cliv3.Flag{
				&cliv3.BoolFlag{
					Name:    "detach",
					Usage:   "run workflow in the background and print workflow and execution id",
					Aliases: []string{"d"},
				},
				&cliv3.StringFlag{
					Name:    "task-queue",
					Usage:   "task queue name",
					Aliases: []string{"t"},
					Sources: cliv3.NewValueSourceChain(cliv3.EnvVar("TEMPORAL_TASK_QUEUE_NAME"), cliv3.EnvVar("TEMPORAL_TASK_QUEUE"), cliv3.EnvVar("TASK_QUEUE_NAME"), cliv3.EnvVar("TASK_QUEUE")),
					Value:   "example-cliv3",
				},
				&cliv3.StringFlag{
					Name:     "input-file",
					Usage:    "path to json-formatted input file",
					Aliases:  []string{"f"},
					Category: "INPUT",
				},
				&cliv3.StringFlag{
					Name:     "name",
					Usage:    "set the value of the operation's \"Name\" parameter",
					Category: "INPUT",
				},
				&cliv3.StringFlag{
					Name:     "description",
					Usage:    "set the value of the operation's \"Description\" parameter",
					Category: "INPUT",
				},
				&cliv3.TimestampFlag{
					Name:     "expires-at",
					Usage:    "set the value of the operation's \"ExpiresAt\" parameter (e.g. \"2017-01-15T01:30:15.01Z\")",
					Category: "INPUT",
					Config:   cliv3.TimestampConfig{Layouts: []string{time.RFC3339Nano}},
				},
			},
			Action: func(ctx context.Context, cmd *cliv3.Command) error {
				tc, err := opts.clientForCommand(ctx, cmd)
				if err != nil {
					return fmt.Errorf("error initializing client for command: %w", err)
				}
				defer tc.Close()
				c := NewExampleServiceClient(tc)
				req, err := UnmarshalCliFlagsToCreateFooInput(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.CreateFooAsync(ctx, req, NewCreateFooOptions().WithStartWorkflowOptions(opts))
				if err != nil {
					return fmt.Errorf("error starting %s workflow: %w", CreateFooWorkflowName, 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 resp, err := run.Get(ctx); err != nil {
					return err
				} else {
					b, err := protojson.Marshal(resp)
					if err != nil {
						return fmt.Errorf("error serializing response json: %w", err)
					}
					var out bytes.Buffer
					if err := json.Indent(&out, b, "", "  "); err != nil {
						return fmt.Errorf("error formatting json: %w", err)
					}
					fmt.Println(out.String())
					return nil
				}
			},
		},
		// sends a test.cliv3.ExampleService.SignalFoo signal to a test.cliv3.ExampleService.CreateFoo workflow, starting it if necessary,
		{
			Name:                   "create-foo-with-signal-foo",
			Usage:                  "sends a test.cliv3.ExampleService.SignalFoo signal to a test.cliv3.ExampleService.CreateFoo workflow, starting it if necessary",
			Category:               "WORKFLOWS",
			UseShortOptionHandling: true,
			Before:                 opts.before,
			After:                  opts.after,
			Flags: []cliv3.Flag{
				&cliv3.BoolFlag{
					Name:    "detach",
					Usage:   "run workflow in the background and print workflow and execution id",
					Aliases: []string{"d"},
				},
				&cliv3.StringFlag{
					Name:     "input-file",
					Usage:    "path to json-formatted input file",
					Aliases:  []string{"f"},
					Category: "INPUT",
				},
				&cliv3.StringFlag{
					Name:     "name",
					Usage:    "set the value of the operation's \"Name\" parameter",
					Category: "INPUT",
				},
				&cliv3.StringFlag{
					Name:     "description",
					Usage:    "set the value of the operation's \"Description\" parameter",
					Category: "INPUT",
				},
				&cliv3.TimestampFlag{
					Name:     "expires-at",
					Usage:    "set the value of the operation's \"ExpiresAt\" parameter (e.g. \"2017-01-15T01:30:15.01Z\")",
					Category: "INPUT",
					Config:   cliv3.TimestampConfig{Layouts: []string{time.RFC3339Nano}},
				},
				&cliv3.StringFlag{
					Name:     "signal-file",
					Usage:    "path to json-formatted input file",
					Aliases:  []string{"s"},
					Category: "SIGNAL",
				},
				&cliv3.Float64Flag{
					Name:     "progress",
					Usage:    "set the value of the operation's \"Progress\" parameter",
					Category: "SIGNAL",
				},
			},
			Action: func(ctx context.Context, cmd *cliv3.Command) error {
				c, err := opts.clientForCommand(ctx, cmd)
				if err != nil {
					return fmt.Errorf("error initializing client for command: %w", err)
				}
				defer c.Close()
				client := NewExampleServiceClient(c)
				req, err := UnmarshalCliFlagsToCreateFooInput(cmd, helpers.UnmarshalCliFlagsOptions{FromFile: "input-file"})
				if err != nil {
					return fmt.Errorf("error unmarshalling request: %w", err)
				}
				signal, err := UnmarshalCliFlagsToSignalFooInput(cmd, helpers.UnmarshalCliFlagsOptions{FromFile: "signal-file"})
				if err != nil {
					return fmt.Errorf("error unmarshalling signal: %w", err)
				}
				run, err := client.CreateFooWithSignalFooAsync(ctx, req, signal)
				if err != nil {
					return fmt.Errorf("error starting %s workflow with %s signal: %w", CreateFooWorkflowName, SignalFooSignalName, 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 resp, err := run.Get(ctx); err != nil {
					return err
				} else {
					b, err := protojson.Marshal(resp)
					if err != nil {
						return fmt.Errorf("error serializing response json: %w", err)
					}
					var out bytes.Buffer
					if err := json.Indent(&out, b, "", "  "); err != nil {
						return fmt.Errorf("error formatting json: %w", err)
					}
					fmt.Println(out.String())
					return nil
				}
			},
		},
		// executes a(n) test.cliv3.ExampleService.UpdateFoo update on a test.cliv3.ExampleService.CreateFoo workflow, starting it if necessary,
		{
			Action: func(ctx context.Context, cmd *cliv3.Command) error {
				c, err := opts.clientForCommand(ctx, cmd)
				if err != nil {
					return fmt.Errorf("error initializing client for command: %w", err)
				}
				defer c.Close()
				client := NewExampleServiceClient(c)
				input, err := UnmarshalCliFlagsToCreateFooInput(cmd, helpers.UnmarshalCliFlagsOptions{FromFile: "input-file"})
				if err != nil {
					return fmt.Errorf("error unmarshalling input: %w", err)
				}
				update, err := UnmarshalCliFlagsToUpdateFooInput(cmd, helpers.UnmarshalCliFlagsOptions{FromFile: "update-file"})
				if err != nil {
					return fmt.Errorf("error unmarshalling update: %w", err)
				}
				handle, _, err := client.CreateFooWithUpdateFooAsync(ctx, input, update)
				if err != nil {
					return fmt.Errorf("error starting workflow with update: %w", 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 out, err := handle.Get(ctx); err != nil {
					return err
				} else {
					b, err := protojson.Marshal(out)
					if err != nil {
						return fmt.Errorf("error serializing response json: %w", err)
					}
					var out bytes.Buffer
					if err := json.Indent(&out, b, "", "  "); err != nil {
						return fmt.Errorf("error formatting json: %w", err)
					}
					fmt.Println(out.String())
					return nil
				}
			},
			After:    opts.after,
			Before:   opts.before,
			Category: "WORKFLOWS",
			Flags: []cliv3.Flag{
				&cliv3.BoolFlag{
					Aliases: []string{"d"},
					Name:    "detach",
					Usage:   "run workflow update in the background and print workflow, execution, and update id",
				},
				&cliv3.StringFlag{
					Aliases:  []string{"f"},
					Category: "INPUT",
					Name:     "input-file",
					Usage:    "path to json-formatted input file",
				},
				&cliv3.StringFlag{
					Name:     "name",
					Usage:    "set the value of the operation's \"Name\" parameter",
					Category: "INPUT",
				},
				&cliv3.StringFlag{
					Name:     "description",
					Usage:    "set the value of the operation's \"Description\" parameter",
					Category: "INPUT",
				},
				&cliv3.TimestampFlag{
					Name:     "expires-at",
					Usage:    "set the value of the operation's \"ExpiresAt\" parameter (e.g. \"2017-01-15T01:30:15.01Z\")",
					Category: "INPUT",
					Config:   cliv3.TimestampConfig{Layouts: []string{time.RFC3339Nano}},
				},
				&cliv3.StringFlag{
					Aliases:  []string{"u"},
					Category: "UPDATE",
					Name:     "update-file",
					Usage:    "path to json-formatted update file",
				},
				&cliv3.Float64Flag{
					Name:     "progress",
					Usage:    "set the value of the operation's \"Progress\" parameter",
					Category: "UPDATE",
				},
			},
			Name:                   "create-foo-with-update-foo",
			Usage:                  "executes a(n) test.cliv3.ExampleService.UpdateFoo update on a test.cliv3.ExampleService.CreateFoo workflow, starting it if necessary",
			UseShortOptionHandling: true,
		},
	}
	if opts.worker != nil {
		commands = append(commands, []*cliv3.Command{
			{
				Name:                   "worker",
				Usage:                  "runs a test.cliv3.ExampleService worker process",
				UseShortOptionHandling: true,
				Before:                 opts.before,
				After:                  opts.after,
				Action: func(ctx context.Context, cmd *cliv3.Command) error {
					c, err := opts.clientForCommand(ctx, cmd)
					if err != nil {
						return fmt.Errorf("error initializing client for command: %w", err)
					}
					defer c.Close()
					w, err := opts.worker(ctx, 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()
					<-ctx.Done()
					return nil
				},
			},
		}...)
	}
	sort.Slice(commands, func(i, j int) bool {
		return commands[i].Name < commands[j].Name
	})
	return commands, nil
}

// UnmarshalCliFlagsToGetFooInput unmarshals a GetFooInput from command line flags
func UnmarshalCliFlagsToGetFooInput(cmd *cliv3.Command, options ...helpers.UnmarshalCliFlagsOptions) (*GetFooInput, error) {
	opts := helpers.FlattenUnmarshalCliFlagsOptions(options...)
	var result GetFooInput
	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)
		}
	}
	return &result, nil
}

// UnmarshalCliFlagsToSignalFooInput unmarshals a SignalFooInput from command line flags
func UnmarshalCliFlagsToSignalFooInput(cmd *cliv3.Command, options ...helpers.UnmarshalCliFlagsOptions) (*SignalFooInput, error) {
	opts := helpers.FlattenUnmarshalCliFlagsOptions(options...)
	var result SignalFooInput
	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("progress"); cmd.IsSet(flag) {
		value := cmd.Float64(flag)
		result.SetProgress(value)
	}
	return &result, nil
}

// UnmarshalCliFlagsToUpdateFooInput unmarshals a UpdateFooInput from command line flags
func UnmarshalCliFlagsToUpdateFooInput(cmd *cliv3.Command, options ...helpers.UnmarshalCliFlagsOptions) (*UpdateFooInput, error) {
	opts := helpers.FlattenUnmarshalCliFlagsOptions(options...)
	var result UpdateFooInput
	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("progress"); cmd.IsSet(flag) {
		value := cmd.Float64(flag)
		result.SetProgress(value)
	}
	return &result, nil
}

// UnmarshalCliFlagsToCreateFooInput unmarshals a CreateFooInput from command line flags
func UnmarshalCliFlagsToCreateFooInput(cmd *cliv3.Command, options ...helpers.UnmarshalCliFlagsOptions) (*CreateFooInput, error) {
	opts := helpers.FlattenUnmarshalCliFlagsOptions(options...)
	var result CreateFooInput
	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.SetName(value)
	}
	if flag := opts.FlagName("description"); cmd.IsSet(flag) {
		value := cmd.String(flag)
		result.SetDescription(value)
	}
	if flag := opts.FlagName("expires-at"); cmd.IsSet(flag) {
		v := cmd.Timestamp(flag)
		value := timestamppb.New(v)
		result.SetExpiresAt(value)
	}
	return &result, nil
}

// WithExampleServiceSchemeTypes registers all ExampleService protobuf types with the given scheme
func WithExampleServiceSchemeTypes() scheme.Option {
	return func(s *scheme.Scheme) {
		s.RegisterType(File_test_cliv3_cliv3_proto.Messages().ByName("GetFooInput"))
		s.RegisterType(File_test_cliv3_cliv3_proto.Messages().ByName("GetFooOutput"))
		s.RegisterType(File_test_cliv3_cliv3_proto.Messages().ByName("SignalFooInput"))
		s.RegisterType(File_test_cliv3_cliv3_proto.Messages().ByName("UpdateFooInput"))
		s.RegisterType(File_test_cliv3_cliv3_proto.Messages().ByName("UpdateFooOutput"))
		s.RegisterType(File_test_cliv3_cliv3_proto.Messages().ByName("CreateFooInput"))
		s.RegisterType(File_test_cliv3_cliv3_proto.Messages().ByName("CreateFooOutput"))
	}
}
