package input

import (
	"context"
	"os"
)

type Input interface {
	Read() []Button
	Close()
}

func New(ctx context.Context) Input {
	foo := randomCharFromRange('a', 'g')
	if p, ok := os.LookupEnv("INPUT_RANDOM_WEIGHT_FILE"); ok && len(p) > 0 {
		foo = randomCharFromWeightFile(p)
	}
	var result Input = NewRandom(foo)
	if os.Getenv("INPUT_KEYBOARD") == "true" {
		result = NewKeyboard()
	}
	if os.Getenv("INPUT_BUFFERED") == "true" {
		result = NewBuffered(ctx, result)
	}
	if p, ok := os.LookupEnv("INPUT_REMAP_FILE"); ok && len(p) > 0 {
		result = NewRemapFromFile(result, p)
	}
	return result
}
