package supervisor

import (
	

	
)

// Start starts the process with the given key from the table. It returns
// ErrNotRunning if the supervisor is not running and ErrProcessExists if the
// process already exists. Otherwise it returns an error from process
// initialization.
func ( *Supervisor[, ]) ( context.Context,  ) (, error) {
	,  := .startProcessForKey(, )
	if  != nil {
		var  
		return , 
	}
	return .proc, nil
}

// Stop stops the process with the given key. It returns ErrProcessNotFound if
// the process does not exist, and an error from running the process otherwise.
func ( *Supervisor[, ]) ( context.Context,  ) error {
	return .stopProcess(, )
}

// Get returns a running process or either a ErrProcessNotFound error if the
// process does not exist or ErrProcessNotRunning is the process exists but is
// not running.
func ( *Supervisor[, ]) ( context.Context,  ) (, error) {
	,  := .processes.Load()
	if ! ||  == nil {
		var  
		return , ErrProcessNotFound
	}
	if .State() != process.StateRunning {
		return .proc, ErrProcessNotRunning
	}
	return .proc, nil
}

// Keys returns a list of all process keys.
func ( *Supervisor[, ]) () [] {
	var  []

	.processes.Range(func( ,  *managedProcess[]) bool {
		 = append(, )
		return true
	})
	return 
}