package runtimegrpc

// RuntimeClientGroup binds one immutable transport/workload authority to all
// neutral Runtime client facets created for one process. The group shares only
// short-lived Identity delegations minted by that exact authority; standalone
// Dial functions retain their existing behavior and public configuration shape.
type RuntimeClientGroup struct {
	config              RuntimeClientConfig
	options             runtimeClientOptions
	identityCoordinator *identityExchangeCoordinator
}

// NewRuntimeClientGroup captures config by value so a caller cannot retarget a
// live group after it has cached a delegation. Each Dial method still performs
// the same complete per-client validation as the standalone Dial function.
func NewRuntimeClientGroup(config RuntimeClientConfig) *RuntimeClientGroup {
	return newRuntimeClientGroup(config, runtimeClientOptions{})
}

// NewRuntimeClientGroupWithOptions adds reviewed behavior without changing the
// released RuntimeClientConfig layout used by existing unkeyed literals.
func NewRuntimeClientGroupWithOptions(config RuntimeClientConfig, values ...RuntimeClientOption) (*RuntimeClientGroup, error) {
	options, err := resolveRuntimeClientOptions(values...)
	if err != nil {
		return nil, err
	}
	return newRuntimeClientGroup(config, options), nil
}

func newRuntimeClientGroup(config RuntimeClientConfig, options runtimeClientOptions) *RuntimeClientGroup {
	return &RuntimeClientGroup{
		config:              config,
		options:             options,
		identityCoordinator: newIdentityExchangeCoordinator(config),
	}
}
