package key

var (
	charToKey = map[byte]Key{
		'a': A,
		'b': B,
		'c': C,
		'd': D,
		'e': E,
		'f': F,
		'g': G,
		'h': H,
		'i': I,
		'j': J,
		'k': K,
		'l': L,
		'm': M,
		'n': N,
		'o': O,
		'p': P,
		'q': Q,
		'r': R,
		's': S,
		't': T,
		'u': U,
		'v': V,
		'w': W,
		'x': X,
		'y': Y,
		'z': Z,
		'1': N1,
		'2': N2,
		'3': N3,
		'4': N4,
		'5': N5,
		'6': N6,
		'7': N7,
		'8': N8,
		'9': N9,
		'0': N0,
	}
	keyToChar = func() map[Key]byte {
		result := map[Key]byte{}
		for k, v := range charToKey {
			result[v] = k
		}
		return result
	}()
)

func ToChar(k Key) byte {
	v, ok := keyToChar[k]
	if !ok {
		return '?'
	}
	return v
}

func FromChar(b byte) Key {
	if b < 'a' {
		b += 'a' - 'A'
	}
	v, ok := charToKey[b]
	if !ok {
		return Undef
	}
	return v
}
