from __future__ import annotations

from typing import Literal

from prettyqt.qt import QtCore
from prettyqt.utils import bidict, get_repr


mod = QtCore.QEvent

TypeStr = Literal[
    "none",
    "action_added",
    "action_changed",
    "action_removed",
    "activation_change",
    "application_activate",
    "application_deactivate",
    "application_font_change",
    "application_layout_direction_change",
    "application_palette_change",
    "application_state_change",
    "application_window_icon_change",
    "child_added",
    "child_polished",
    "child_removed",
    "clipboard",
    "close",
    "close_software_input_panel",
    "contents_rect_change",
    "context_menu",
    "cursor_change",
    "deferred_delete",
    "drag_enter",
    "drag_leave",
    "drag_move",
    "drop",
    "dynamic_property_change",
    "enabled_change",
    "enter",
    "enter_whats_this_mode",
    "expose",
    "file_open",
    "focus_in",
    "focus_out",
    "focus_about_to_change",
    "font_change",
    "gesture",
    "gesture_override",
    "grab_keyboard",
    "grab_mouse",
    "graphics_scene_context_menu",
    "graphics_scene_drag_enter",
    "graphics_scene_drag_leave",
    "graphics_scene_drag_move",
    "graphics_scene_drop",
    "graphics_scene_help",
    "graphics_scene_hover_enter",
    "graphics_scene_hover_leave",
    "graphics_scene_hover_move",
    "graphics_scene_mouse_double_click",
    "graphics_scene_mouse_move",
    "graphics_scene_mouse_press",
    "graphics_scene_mouse_release",
    "graphics_scene_move",
    "graphics_scene_resize",
    "graphics_scene_wheel",
    "hide",
    "hide_to_parent",
    "hover_enter",
    "hover_leave",
    "hover_move",
    "icon_drag",
    "icon_text_change",
    "input_method",
    "input_method_query",
    "keyboard_layout_change",
    "key_press",
    "key_release",
    "language_change",
    "layout_direction_change",
    "layout_request",
    "leave",
    "leave_whats_this_mode",
    "locale_change",
    "non_client_area_mouse_button_dbl_click",
    "non_client_area_mouse_button_press",
    "non_client_area_mouse_button_release",
    "non_client_area_mouse_move",
    "mac_size_change",
    "meta_call",
    "modified_change",
    "mouse_button_dbl_click",
    "mouse_button_press",
    "mouse_button_release",
    "mouse_move",
    "mouse_tracking_change",
    "move",
    "native_gesture",
    "orientation_change",
    "paint",
    "palette_change",
    "parent_about_to_change",
    "parent_change",
    "platform_panel",
    "platform_surface",
    "polish",
    "polish_request",
    "query_whats_this",
    "quit",
    "read_only_change",
    "request_software_input_panel",
    "resize",
    "scroll_prepare",
    "scroll",
    "shortcut",
    "shortcut_override",
    "show",
    "show_to_parent",
    "sock_act",
    "state_machine_signal",
    "state_machine_wrapped",
    "status_tip",
    "style_change",
    "tablet_move",
    "tablet_press",
    "tablet_release",
    "tablet_enter_proximity",
    "tablet_leave_proximity",
    "tablet_tracking_change",
    "thread_change",
    "timer",
    "tool_bar_change",
    "tool_tip",
    "tool_tip_change",
    "touch_begin",
    "touch_cancel",
    "touch_end",
    "touch_update",
    "ungrab_keyboard",
    "ungrab_mouse",
    "update_later",
    "update_request",
    "whats_this",
    "whats_this_clicked",
    "wheel",
    "win_event_act",
    "window_activate",
    "window_blocked",
    "window_deactivate",
    "window_icon_change",
    "window_state_change",
    "window_title_change",
    "window_unblocked",
    "win_id_change",
    "z_order_change",
]


TYPE: bidict[TypeStr, mod.Type] = bidict(
    none=mod.Type.None_,
    action_added=mod.Type.ActionAdded,
    action_changed=mod.Type.ActionChanged,
    action_removed=mod.Type.ActionRemoved,
    activation_change=mod.Type.ActivationChange,
    application_activate=mod.Type.ApplicationActivate,
    application_deactivate=mod.Type.ApplicationDeactivate,
    application_font_change=mod.Type.ApplicationFontChange,
    application_layout_direction_change=mod.Type.ApplicationLayoutDirectionChange,
    application_palette_change=mod.Type.ApplicationPaletteChange,
    application_state_change=mod.Type.ApplicationStateChange,
    application_window_icon_change=mod.Type.ApplicationWindowIconChange,
    child_added=mod.Type.ChildAdded,
    child_polished=mod.Type.ChildPolished,
    child_removed=mod.Type.ChildRemoved,
    clipboard=mod.Type.Clipboard,
    close=mod.Type.Close,
    close_software_input_panel=mod.Type.CloseSoftwareInputPanel,
    contents_rect_change=mod.Type.ContentsRectChange,
    context_menu=mod.Type.ContextMenu,
    cursor_change=mod.Type.CursorChange,
    deferred_delete=mod.Type.DeferredDelete,
    drag_enter=mod.Type.DragEnter,
    drag_leave=mod.Type.DragLeave,
    drag_move=mod.Type.DragMove,
    drop=mod.Type.Drop,
    dynamic_property_change=mod.Type.DynamicPropertyChange,
    enabled_change=mod.Type.EnabledChange,
    enter=mod.Type.Enter,
    # enter_edit_focus=mod.Type.EnterEditFocus,
    # leave_edit_focus=mod.Type.LeaveEditFocus ,
    enter_whats_this_mode=mod.Type.EnterWhatsThisMode,
    expose=mod.Type.Expose,
    file_open=mod.Type.FileOpen,
    focus_in=mod.Type.FocusIn,
    focus_out=mod.Type.FocusOut,
    focus_about_to_change=mod.Type.FocusAboutToChange,
    font_change=mod.Type.FontChange,
    gesture=mod.Type.Gesture,
    gesture_override=mod.Type.GestureOverride,
    grab_keyboard=mod.Type.GrabKeyboard,
    grab_mouse=mod.Type.GrabMouse,
    graphics_scene_context_menu=mod.Type.GraphicsSceneContextMenu,
    graphics_scene_drag_enter=mod.Type.GraphicsSceneDragEnter,
    graphics_scene_drag_leave=mod.Type.GraphicsSceneDragLeave,
    graphics_scene_drag_move=mod.Type.GraphicsSceneDragMove,
    graphics_scene_drop=mod.Type.GraphicsSceneDrop,
    graphics_scene_help=mod.Type.GraphicsSceneHelp,
    graphics_scene_hover_enter=mod.Type.GraphicsSceneHoverEnter,
    graphics_scene_hover_leave=mod.Type.GraphicsSceneHoverLeave,
    graphics_scene_hover_move=mod.Type.GraphicsSceneHoverMove,
    graphics_scene_mouse_double_click=mod.Type.GraphicsSceneMouseDoubleClick,
    graphics_scene_mouse_move=mod.Type.GraphicsSceneMouseMove,
    graphics_scene_mouse_press=mod.Type.GraphicsSceneMousePress,
    graphics_scene_mouse_release=mod.Type.GraphicsSceneMouseRelease,
    graphics_scene_move=mod.Type.GraphicsSceneMove,
    graphics_scene_resize=mod.Type.GraphicsSceneResize,
    graphics_scene_wheel=mod.Type.GraphicsSceneWheel,
    hide=mod.Type.Hide,
    hide_to_parent=mod.Type.HideToParent,
    hover_enter=mod.Type.HoverEnter,
    hover_leave=mod.Type.HoverLeave,
    hover_move=mod.Type.HoverMove,
    icon_drag=mod.Type.IconDrag,
    icon_text_change=mod.Type.IconTextChange,
    input_method=mod.Type.InputMethod,
    input_method_query=mod.Type.InputMethodQuery,
    keyboard_layout_change=mod.Type.KeyboardLayoutChange,
    key_press=mod.Type.KeyPress,
    key_release=mod.Type.KeyRelease,
    language_change=mod.Type.LanguageChange,
    layout_direction_change=mod.Type.LayoutDirectionChange,
    layout_request=mod.Type.LayoutRequest,
    leave=mod.Type.Leave,
    leave_whats_this_mode=mod.Type.LeaveWhatsThisMode,
    locale_change=mod.Type.LocaleChange,
    non_client_area_mouse_button_dbl_click=mod.Type.NonClientAreaMouseButtonDblClick,
    non_client_area_mouse_button_press=mod.Type.NonClientAreaMouseButtonPress,
    non_client_area_mouse_button_release=mod.Type.NonClientAreaMouseButtonRelease,
    non_client_area_mouse_move=mod.Type.NonClientAreaMouseMove,
    mac_size_change=mod.Type.MacSizeChange,
    meta_call=mod.Type.MetaCall,
    modified_change=mod.Type.ModifiedChange,
    mouse_button_dbl_click=mod.Type.MouseButtonDblClick,
    mouse_button_press=mod.Type.MouseButtonPress,
    mouse_button_release=mod.Type.MouseButtonRelease,
    mouse_move=mod.Type.MouseMove,
    mouse_tracking_change=mod.Type.MouseTrackingChange,
    move=mod.Type.Move,
    native_gesture=mod.Type.NativeGesture,
    orientation_change=mod.Type.OrientationChange,
    paint=mod.Type.Paint,
    palette_change=mod.Type.PaletteChange,
    parent_about_to_change=mod.Type.ParentAboutToChange,
    parent_change=mod.Type.ParentChange,
    platform_panel=mod.Type.PlatformPanel,
    platform_surface=mod.Type.PlatformSurface,
    polish=mod.Type.Polish,
    polish_request=mod.Type.PolishRequest,
    query_whats_this=mod.Type.QueryWhatsThis,
    quit=mod.Type.Quit,
    read_only_change=mod.Type.ReadOnlyChange,
    request_software_input_panel=mod.Type.RequestSoftwareInputPanel,
    resize=mod.Type.Resize,
    scroll_prepare=mod.Type.ScrollPrepare,
    scroll=mod.Type.Scroll,
    shortcut=mod.Type.Shortcut,
    shortcut_override=mod.Type.ShortcutOverride,
    show=mod.Type.Show,
    show_to_parent=mod.Type.ShowToParent,
    sock_act=mod.Type.SockAct,
    state_machine_signal=mod.Type.StateMachineSignal,
    state_machine_wrapped=mod.Type.StateMachineWrapped,
    status_tip=mod.Type.StatusTip,
    style_change=mod.Type.StyleChange,
    tablet_move=mod.Type.TabletMove,
    tablet_press=mod.Type.TabletPress,
    tablet_release=mod.Type.TabletRelease,
    tablet_enter_proximity=mod.Type.TabletEnterProximity,
    tablet_leave_proximity=mod.Type.TabletLeaveProximity,
    tablet_tracking_change=mod.Type.TabletTrackingChange,
    thread_change=mod.Type.ThreadChange,
    timer=mod.Type.Timer,
    tool_bar_change=mod.Type.ToolBarChange,
    tool_tip=mod.Type.ToolTip,
    tool_tip_change=mod.Type.ToolTipChange,
    touch_begin=mod.Type.TouchBegin,
    touch_cancel=mod.Type.TouchCancel,
    touch_end=mod.Type.TouchEnd,
    touch_update=mod.Type.TouchUpdate,
    ungrab_keyboard=mod.Type.UngrabKeyboard,
    ungrab_mouse=mod.Type.UngrabMouse,
    update_later=mod.Type.UpdateLater,
    update_request=mod.Type.UpdateRequest,
    whats_this=mod.Type.WhatsThis,
    whats_this_clicked=mod.Type.WhatsThisClicked,
    wheel=mod.Type.Wheel,
    win_event_act=mod.Type.WinEventAct,
    window_activate=mod.Type.WindowActivate,
    window_blocked=mod.Type.WindowBlocked,
    window_deactivate=mod.Type.WindowDeactivate,
    window_icon_change=mod.Type.WindowIconChange,
    window_state_change=mod.Type.WindowStateChange,
    window_title_change=mod.Type.WindowTitleChange,
    window_unblocked=mod.Type.WindowUnblocked,
    win_id_change=mod.Type.WinIdChange,
    z_order_change=mod.Type.ZOrderChange,
)

MouseButtonTypeStr = Literal["press", "release", "double_click", "move"]

MouseButtonType: bidict[MouseButtonTypeStr, QtCore.QEvent.Type] = bidict(
    press=QtCore.QEvent.Type.MouseButtonPress,
    release=QtCore.QEvent.Type.MouseButtonRelease,
    double_click=QtCore.QEvent.Type.MouseButtonDblClick,
    move=QtCore.QEvent.Type.MouseMove,
)


class Event(QtCore.QEvent):
    """The base class of all event classes. Event objects contain event parameters."""

    def __repr__(self):
        return get_repr(self, self.type())
