import sys
from unittest import mock
from pprint import PrettyPrinter

sys.modules["evdev.ecodes"] = mock.Mock()
from evdev import ecodes_runtime as ecodes

pprint = PrettyPrinter(indent=2, sort_dicts=True, width=120).pprint


print("# Automatically generated by evdev.genecodes_py")
print()
print('"""')
print(ecodes.__doc__.strip())
print('"""')

print()
print("from typing import Final")
print()

for name, value in ecodes.ecodes.items():
    print(f"{name}: Final[int] = {value}")
print()

entries = [
    ("ecodes", "dict[str, int]", "#: Mapping of names to values."),
    ("bytype", "dict[int, dict[int, str | tuple[str]]]", "#: Mapping of event types to other value/name mappings."),
    ("keys",   "dict[int, str | tuple[str]]", "#: Keys are a combination of all BTN and KEY codes."),
    ("KEY",    "dict[int, str | tuple[str]]", None),
    ("ABS",    "dict[int, str | tuple[str]]", None),
    ("REL",    "dict[int, str | tuple[str]]", None),
    ("SW",     "dict[int, str | tuple[str]]", None),
    ("MSC",    "dict[int, str | tuple[str]]", None),
    ("LED",    "dict[int, str | tuple[str]]", None),
    ("BTN",    "dict[int, str | tuple[str]]", None),
    ("REP",    "dict[int, str | tuple[str]]", None),
    ("SND",    "dict[int, str | tuple[str]]", None),
    ("ID",     "dict[int, str | tuple[str]]", None),
    ("EV",     "dict[int, str | tuple[str]]", None),
    ("BUS",    "dict[int, str | tuple[str]]", None),
    ("SYN",    "dict[int, str | tuple[str]]", None),
    ("FF",     "dict[int, str | tuple[str]]", None),
    ("UI_FF",  "dict[int, str | tuple[str]]", None),
    ("FF_STATUS",  "dict[int, str | tuple[str]]", None),
    ("INPUT_PROP", "dict[int, str | tuple[str]]", None)
]

for key, annotation, doc in entries:
    if doc:
        print(doc)

    print(f"{key}: {annotation} = ", end="")
    pprint(getattr(ecodes, key))
    print()