package inputrc

import (
	
)

// Handler is the handler interface.
type Handler interface {
	// ReadFile reads a file.
	ReadFile(name string) ([]byte, error)
	// Do handles $constructs.
	Do(typ string, param string) error
	// Set sets the value.
	Set(name string, value interface{}) error
	// Get gets the value.
	Get(name string) interface{}
	// Bind binds a key sequence to an action for the current keymap.
	Bind(keymap, sequence, action string, macro bool) error
}

// Config is a inputrc config handler.
type Config struct {
	ReadFileFunc func(string) ([]byte, error)
	Vars         map[string]interface{}
	Binds        map[string]map[string]Bind
	Funcs        map[string]func(string, string) error
}

// NewConfig creates a new inputrc config.
func () *Config {
	return &Config{
		Vars:  make(map[string]interface{}),
		Binds: make(map[string]map[string]Bind),
		Funcs: make(map[string]func(string, string) error),
	}
}

// NewDefaultConfig creates a new inputrc config with default values.
func ( ...ConfigOption) *Config {
	 := &Config{
		ReadFileFunc: os.ReadFile,
		Vars:         DefaultVars(),
		Binds:        DefaultBinds(),
		Funcs:        make(map[string]func(string, string) error),
	}
	for ,  := range  {
		()
	}

	return 
}

// ReadFile satisfies the Handler interface.
func ( *Config) ( string) ([]byte, error) {
	if .ReadFileFunc != nil {
		return .ReadFileFunc()
	}

	return nil, os.ErrNotExist
}

// Do satisfies the Handler interface.
func ( *Config) (,  string) error {
	if ,  := .Funcs[];  {
		return (, )
	}

	if ,  := .Funcs[""];  {
		return (, )
	}

	return nil
}

// Get satisfies the Handler interface.
func ( *Config) ( string) interface{} {
	return .Vars[]
}

// Set satisfies the Handler interface.
func ( *Config) ( string,  interface{}) error {
	.Vars[] = 
	return nil
}

// Bind satisfies the Handler interface.
func ( *Config) (, ,  string,  bool) error {
	if .Binds[] == nil {
		.Binds[] = make(map[string]Bind)
	}

	.Binds[][] = Bind{
		Action: ,
		Macro:  ,
	}

	return nil
}

// GetString returns the var name as a string.
func ( *Config) ( string) string {
	if ,  := .Vars[];  {
		if ,  := .(string);  {
			return 
		}
	}

	return ""
}

// GetInt returns the var name as a int.
func ( *Config) ( string) int {
	if ,  := .Vars[];  {
		if ,  := .(int);  {
			return 
		}
	}

	return 0
}

// GetBool returns the var name as a bool.
func ( *Config) ( string) bool {
	if ,  := .Vars[];  {
		if ,  := .(bool);  {
			return 
		}
	}

	return false
}

// Bind represents a key binding.
type Bind struct {
	Action string
	Macro  bool
}

// ConfigOption is a inputrc config handler option.
type ConfigOption func(*Config)

// WithConfigReadFileFunc is a inputrc config option to set the func used
// for ReadFile operations.
func ( func(string) ([]byte, error)) ConfigOption {
	return func( *Config) {
		.ReadFileFunc = 
	}
}