"""WizardKit: Auto Repair Tool"""
# vim: sts=2 sw=2 ts=2

from typing import Any

import wk


# Classes
REBOOT_STR = wk.ui.ansi.color_string('Reboot', 'YELLOW')
class MenuEntry():
  """Simple class to allow cleaner code below."""
  def __init__(
      self,
      name: str,
      function: str | None = None,
      selected: bool = True,
      **kwargs):
    self.name: str = name
    self.details: dict[str, Any] = {
      'Function': function,
      'Selected': selected,
      **kwargs,
      }


# STATIC VARIABLES
BASE_MENUS = {
  'Groups': {
    'Backup Settings': (
      MenuEntry('Enable RegBack',           'auto_enable_regback'),
      MenuEntry('Enable System Restore',    'auto_system_restore_enable'),
      MenuEntry('Set System Restore Size',  'auto_system_restore_set_size'),
      MenuEntry('Create System Restore',    'auto_system_restore_create'),
      MenuEntry('Backup Browsers',          'auto_backup_browser_profiles'),
      MenuEntry('Backup Power Plans',       'auto_backup_power_plans'),
      MenuEntry('Reset Power Plans',        'auto_reset_power_plans'),
      MenuEntry('Set Custom Power Plan',    'auto_set_custom_power_plan'),
      MenuEntry('Backup Registry',          'auto_backup_registry'),
      ),
    'Windows Repairs': (
      MenuEntry('Disable Windows Updates',  'auto_windows_updates_disable'),
      MenuEntry('Reset Windows Updates',    'auto_windows_updates_reset'),
      MenuEntry(REBOOT_STR,                 'auto_reboot'),
      MenuEntry('CHKDSK',                   'auto_chkdsk'),
      MenuEntry('DISM RestoreHealth',       'auto_dism'),
      MenuEntry('SFC Scan',                 'auto_sfc'),
      MenuEntry('Fix File Associations',    'auto_fix_file_associations'),
      MenuEntry('Clear Proxy Settings',     'auto_reset_proxy'),
      MenuEntry('Disable Pending Renames',  'auto_disable_pending_renames'),
      MenuEntry('Registry Repairs',         'auto_repair_registry'),
      MenuEntry('Reset UAC',                'auto_restore_uac_defaults'),
      MenuEntry('Reset Windows Policies',   'auto_reset_windows_policies'),
      ),
    'Malware Cleanup': (
      MenuEntry('Disable Defender Scans',   'auto_disable_defender'),
      MenuEntry('BleachBit',                'auto_bleachbit'),
      MenuEntry('HitmanPro',                'auto_hitmanpro'),
      MenuEntry('KVRT',                     'auto_kvrt'),
      MenuEntry('EmsisoftCmd',              'auto_emsisoft_cmd_run'),
      MenuEntry(REBOOT_STR,                 'auto_reboot'),
      MenuEntry('EmsisoftCmd (Uninstall)',  'auto_emsisoft_cmd_uninstall'),
      MenuEntry('Enable Defender Scans',    'auto_enable_defender'),
      MenuEntry('Windows Defender',         'auto_microsoft_defender'),
      MenuEntry('Remove Custom Power Plan', 'auto_remove_power_plan'),
      ),
    'Manual Steps': (
      MenuEntry('Malwarebytes (Install)',   'auto_mbam_install'),
      MenuEntry(REBOOT_STR,                 'auto_reboot'),
      MenuEntry('AdwCleaner',               'auto_adwcleaner'),
      MenuEntry('Malwarebytes (Run)',       'auto_mbam_run'),
      MenuEntry('Malwarebytes (Uninstall)', 'auto_mbam_uninstall'),
      MenuEntry('UninstallView',            'auto_uninstallview'),
      MenuEntry('Enable Windows Updates',   'auto_windows_updates_enable'),
      ),
    },
  'Options': (
    MenuEntry('Kill Explorer', selected=False),
    MenuEntry('Run RKill'),
    MenuEntry('Run TDSSKiller (once)'),
    MenuEntry('Sync Clock'),
    MenuEntry('Use Autologon', selected=False),
    ),
  'Actions': (
    MenuEntry('Load Preset'),
    MenuEntry('Options'),
    MenuEntry('Start', Separator=True),
    MenuEntry('Quit'),
    ),
  }
PRESETS = {
  'Default': { # Will be expanded at runtime using BASE_MENUS
    'Options': (
      'Run RKill',
      'Run TDSSKiller (once)',
      'Sync Clock',
      ),
    },
  'Data Transfer (to a clean Windows install)': {
    'Backup Settings': (
      'Enable RegBack',
      'Enable System Restore',
      'Set System Restore Size',
      'Reset Power Plans',
      'Set Custom Power Plan',
      ),
    'Malware Cleanup': (
      'Disable Defender Scans',
      'BleachBit',
      'HitmanPro',
      'KVRT',
      'Enable Defender Scans',
      'Remove Custom Power Plan',
      ),
    'Manual Steps': (
      'Malwarebytes (Install)',
       REBOOT_STR,
      'AdwCleaner',
      'Malwarebytes (Run)',
      'Malwarebytes (Uninstall)',
      'Enable Windows Updates',
      ),
    'Options': (
      'Run RKill',
      'Run TDSSKiller (once)',
      'Sync Clock',
      ),
    },
  'Light Malware/Virus Cleanup': {
    'Backup Settings': (
      'Enable RegBack',
      'Enable System Restore',
      'Set System Restore Size',
      'Create System Restore',
      'Backup Browsers',
      'Backup Power Plans',
      'Reset Power Plans',
      'Set Custom Power Plan',
      'Backup Registry',
      ),
    'Windows Repairs': (
      'Disable Windows Updates',
      'Reset Windows Updates',
       REBOOT_STR,
      'CHKDSK',
      'DISM RestoreHealth',
      'SFC Scan',
      'Fix File Associations',
      'Clear Proxy Settings',
      'Disable Pending Renames',
      'Registry Repairs',
      'Reset UAC',
      'Reset Windows Policies',
      ),
    'Malware Cleanup': (
      'Disable Defender Scans',
      'BleachBit',
      'HitmanPro',
      'KVRT',
      'Enable Defender Scans',
      'Remove Custom Power Plan',
      ),
    'Manual Steps': (
      'Malwarebytes (Install)',
       REBOOT_STR,
      'AdwCleaner',
      'Malwarebytes (Run)',
      'Malwarebytes (Uninstall)',
      'UninstallView',
      'Enable Windows Updates',
      ),
    'Options': (
      'Run RKill',
      'Run TDSSKiller (once)',
      'Sync Clock',
      ),
    },
  'Custom': {}, # Will remain empty at runtime
  }

if __name__ == '__main__':
  try:
    wk.repairs.win.run_auto_repairs(BASE_MENUS, PRESETS)
  except KeyboardInterrupt:
    wk.ui.cli.abort()
  except SystemExit:
    raise
  except: # noqa: E722
    wk.ui.cli.major_exception()
