// Code generated by wit-bindgen-go. DO NOT EDIT.

// Package runtime represents the imported interface "wasi:config/runtime@0.2.0-draft".
package runtime

import (
	"github.com/bytecodealliance/wasm-tools-go/cm"
)

// ConfigError represents the variant "wasi:config/runtime@0.2.0-draft#config-error".
//
// An error type that encapsulates the different errors that can occur fetching config
//
//	variant config-error {
//		upstream(string),
//		io(string),
//	}
type ConfigError cm.Variant[uint8, string, string]

// ConfigErrorUpstream returns a [ConfigError] of case "upstream".
//
// This indicates an error from an "upstream" config source.
// As this could be almost _anything_ (such as Vault, Kubernetes ConfigMaps, KeyValue
// buckets, etc),
// the error message is a string.
func ConfigErrorUpstream(data string) ConfigError {
	return cm.New[ConfigError](0, data)
}

// Upstream returns a non-nil *[string] if [ConfigError] represents the variant case "upstream".
func (self *ConfigError) Upstream() *string {
	return cm.Case[string](self, 0)
}

// ConfigErrorIO returns a [ConfigError] of case "io".
//
// This indicates an error from an I/O operation.
// As this could be almost _anything_ (such as a file read, network connection, etc),
// the error message is a string.
// Depending on how this ends up being consumed,
// we may consider moving this to use the `wasi:io/error` type instead.
// For simplicity right now in supporting multiple implementations, it is being left
// as a string.
func ConfigErrorIO(data string) ConfigError {
	return cm.New[ConfigError](1, data)
}

// IO returns a non-nil *[string] if [ConfigError] represents the variant case "io".
func (self *ConfigError) IO() *string {
	return cm.Case[string](self, 1)
}

var stringsConfigError = [2]string{
	"upstream",
	"io",
}

// String implements [fmt.Stringer], returning the variant case name of v.
func (v ConfigError) String() string {
	return stringsConfigError[v.Tag()]
}

// Get represents the imported function "get".
//
// Gets a single opaque config value set at the given key if it exists
//
//	get: func(key: string) -> result<option<string>, config-error>
//
//go:nosplit
func Get(key string) (result cm.Result[OptionStringShape, cm.Option[string], ConfigError]) {
	key0, key1 := cm.LowerString(key)
	wasmimport_Get((*uint8)(key0), (uint32)(key1), &result)
	return
}

// GetAll represents the imported function "get-all".
//
// Gets a list of all set config data
//
//	get-all: func() -> result<list<tuple<string, string>>, config-error>
//
//go:nosplit
func GetAll() (result cm.Result[ConfigErrorShape, cm.List[[2]string], ConfigError]) {
	wasmimport_GetAll(&result)
	return
}
