use super::*;
use std::collections::HashSet;

const HELP_ACTIONS: &[Action] = &[
    Action::ToggleWhiteboard,
    Action::ToggleBlackboard,
    Action::ReturnToTransparent,
    Action::Board1,
    Action::Board2,
    Action::Board3,
    Action::Board4,
    Action::Board5,
    Action::Board6,
    Action::Board7,
    Action::Board8,
    Action::Board9,
    Action::BoardPrev,
    Action::BoardNext,
    Action::BoardNew,
    Action::BoardDelete,
    Action::BoardPicker,
    Action::PagePrev,
    Action::PageNext,
    Action::PageNew,
    Action::PageDuplicate,
    Action::PageDelete,
    Action::BoardPrev,
    Action::BoardNext,
    Action::BoardNew,
    Action::BoardDelete,
    Action::SetColorRed,
    Action::SetColorGreen,
    Action::SetColorBlue,
    Action::SetColorYellow,
    Action::SetColorOrange,
    Action::SetColorPink,
    Action::SetColorWhite,
    Action::SetColorBlack,
    Action::SelectSelectionTool,
    Action::SelectPenTool,
    Action::SelectLineTool,
    Action::SelectRectTool,
    Action::SelectEllipseTool,
    Action::SelectArrowTool,
    Action::ToggleHighlightTool,
    Action::SelectMarkerTool,
    Action::SelectEraserTool,
    Action::IncreaseThickness,
    Action::DecreaseThickness,
    Action::SelectAll,
    Action::DuplicateSelection,
    Action::CopySelection,
    Action::PasteSelection,
    Action::DeleteSelection,
    Action::ToggleSelectionProperties,
    Action::IncreaseFontSize,
    Action::DecreaseFontSize,
    Action::EnterTextMode,
    Action::EnterStickyNoteMode,
    Action::ToggleFill,
    Action::ZoomIn,
    Action::ZoomOut,
    Action::ResetZoom,
    Action::ToggleZoomLock,
    Action::RefreshZoomCapture,
    Action::ClearCanvas,
    Action::Undo,
    Action::ToggleClickHighlight,
    Action::OpenContextMenu,
    Action::Exit,
    Action::ToggleHelp,
    Action::ToggleToolbar,
    Action::TogglePresenterMode,
    Action::OpenConfigurator,
    Action::ToggleStatusBar,
    Action::ToggleFrozenMode,
    Action::CaptureClipboardFull,
    Action::CaptureFileFull,
    Action::CaptureClipboardSelection,
    Action::CaptureFileSelection,
    Action::CaptureActiveWindow,
    Action::CaptureSelection,
    Action::OpenCaptureFolder,
];

const TOOLBAR_ACTIONS: &[Action] = &[
    Action::SelectPenTool,
    Action::SelectLineTool,
    Action::SelectRectTool,
    Action::SelectEllipseTool,
    Action::SelectArrowTool,
    Action::SelectSelectionTool,
    Action::SelectMarkerTool,
    Action::SelectHighlightTool,
    Action::SelectEraserTool,
    Action::EnterTextMode,
    Action::EnterStickyNoteMode,
    Action::ToggleFill,
    Action::Undo,
    Action::Redo,
    Action::UndoAll,
    Action::RedoAll,
    Action::UndoAllDelayed,
    Action::RedoAllDelayed,
    Action::ClearCanvas,
    Action::PagePrev,
    Action::PageNext,
    Action::PageNew,
    Action::PageDuplicate,
    Action::PageDelete,
    Action::ToggleHighlightTool,
    Action::ToggleFrozenMode,
    Action::ZoomIn,
    Action::ZoomOut,
    Action::ResetZoom,
    Action::ToggleZoomLock,
    Action::ApplyPreset1,
    Action::ApplyPreset2,
    Action::ApplyPreset3,
    Action::ApplyPreset4,
    Action::ApplyPreset5,
    Action::SavePreset1,
    Action::SavePreset2,
    Action::SavePreset3,
    Action::SavePreset4,
    Action::SavePreset5,
    Action::ClearPreset1,
    Action::ClearPreset2,
    Action::ClearPreset3,
    Action::ClearPreset4,
    Action::ClearPreset5,
    Action::OpenConfigurator,
];

const PALETTE_ACTIONS: &[Action] = &[
    Action::Exit,
    Action::EnterTextMode,
    Action::EnterStickyNoteMode,
    Action::ClearCanvas,
    Action::Undo,
    Action::Redo,
    Action::SelectSelectionTool,
    Action::SelectPenTool,
    Action::SelectLineTool,
    Action::SelectRectTool,
    Action::SelectEllipseTool,
    Action::SelectArrowTool,
    Action::SelectHighlightTool,
    Action::SelectMarkerTool,
    Action::SelectEraserTool,
    Action::ToggleEraserMode,
    Action::IncreaseThickness,
    Action::DecreaseThickness,
    Action::ToggleFill,
    Action::ToggleWhiteboard,
    Action::ToggleBlackboard,
    Action::ReturnToTransparent,
    Action::PagePrev,
    Action::PageNext,
    Action::PageNew,
    Action::ToggleHelp,
    Action::ToggleToolbar,
    Action::ToggleStatusBar,
    Action::TogglePresenterMode,
    Action::ToggleClickHighlight,
    Action::OpenConfigurator,
    Action::ReplayTour,
    Action::SetColorRed,
    Action::SetColorGreen,
    Action::SetColorBlue,
    Action::SetColorYellow,
    Action::SetColorOrange,
    Action::SetColorPink,
    Action::SetColorWhite,
    Action::SetColorBlack,
    Action::CaptureClipboardFull,
    Action::CaptureFileFull,
    Action::OpenCaptureFolder,
    Action::ToggleFrozenMode,
    Action::ZoomIn,
    Action::ZoomOut,
    Action::ResetZoom,
    Action::ToggleZoomLock,
    Action::SelectAll,
    Action::DeleteSelection,
    Action::DuplicateSelection,
    Action::CopySelection,
    Action::PasteSelection,
    Action::ApplyPreset1,
    Action::ApplyPreset2,
    Action::ApplyPreset3,
    Action::ApplyPreset4,
    Action::ApplyPreset5,
];

fn assert_actions_have_flag(
    actions: &[Action],
    flag_name: &str,
    check: impl Fn(&ActionMeta) -> bool,
) {
    let mut seen = HashSet::new();
    for action in actions {
        if !seen.insert(*action) {
            continue;
        }
        let meta =
            action_meta(*action).unwrap_or_else(|| panic!("missing ActionMeta for {:?}", action));
        assert!(check(meta), "Action {:?} missing {}", action, flag_name);
    }
}

#[test]
fn action_meta_covers_surface_actions() {
    assert_actions_have_flag(HELP_ACTIONS, "in_help", |meta| meta.in_help);
    assert_actions_have_flag(TOOLBAR_ACTIONS, "in_toolbar", |meta| meta.in_toolbar);
    assert_actions_have_flag(PALETTE_ACTIONS, "in_command_palette", |meta| {
        meta.in_command_palette
    });
}
