
const securityCheckMapping: {[key: string]: string} = {
  is_host_an_ipv4: 'Host is an IPv4 Address',
  is_uncommon_host_length: 'Uncommon Host Length',
  is_uncommon_dash_char_count: 'Uncommon Number of Dashes in Host',
  is_uncommon_dot_char_count: 'Uncommon Number of Dots in Host',
  is_uncommon_host_name: 'Uncommon Hostname',
  is_suspicious_url_pattern: 'Suspicious URL Pattern',
  is_suspicious_file_extension: 'Suspicious File Extension',
  is_robots_noindex: 'Robots Noindex',
  is_suspended_page: 'Suspended Page',
  is_most_abused_tld: 'Top-Level Domain Highly Abused',
  is_uncommon_clickable_url: 'Uncommon Clickable URL',
  is_phishing_heuristic: 'Phishing Heuristic Detected',
  is_possible_emotet: 'Possible Emotet Infection',
  is_redirect_to_search_engine: 'Redirects to Search Engine',
  is_redirect_to_wikipedia: 'Redirects to Wikipedia',
  is_http_status_error: 'HTTP Status Error',
  is_http_server_error: 'HTTP Server Error',
  is_http_client_error: 'HTTP Client Error',
  is_suspicious_content: 'Suspicious Content Detected',
  is_url_accessible: 'URL is Accessible',
  is_empty_page_title: 'Empty Page Title',
  is_empty_page_content: 'Empty Page Content',
  is_domain_ipv4_assigned: 'Domain IPv4 is Assigned',
  is_domain_ipv4_private: 'Domain IPv4 is Private',
  is_domain_ipv4_loopback: 'Domain IPv4 is Loopback',
  is_domain_ipv4_reserved: 'Domain IPv4 is Reserved',
  is_domain_ipv4_valid: 'Domain IPv4 is Valid',
  is_domain_blacklisted: 'Domain is Blacklisted',
  is_suspicious_domain: 'Suspicious Domain',
  is_sinkholed_domain: 'Sinkholed Domain',
  is_defaced_heuristic: 'Defacement Heuristic Detected',
  is_masked_file: 'Masked File Detected',
  is_risky_geo_location: 'Risky Geographical Location',
  is_china_country: 'Located in China',
  is_nigeria_country: 'Located in Nigeria',
  is_non_standard_port: 'Non-standard Port Used',
  is_email_address_on_url_query: 'Email Address Found in URL Query',
  is_directory_listing: 'Directory Listing Enabled',
  is_exe_on_directory_listing: '.EXE File Found in Directory Listing',
  is_zip_on_directory_listing: '.ZIP File Found in Directory Listing',
  is_php_on_directory_listing: '.PHP File Found in Directory Listing',
  is_doc_on_directory_listing: '.DOC File Found in Directory Listing',
  is_pdf_on_directory_listing: '.PDF File Found in Directory Listing',
  is_apk_on_directory_listing: '.APK File Found in Directory Listing',
  is_linux_elf_file: 'Linux ELF File Detected',
  is_linux_elf_file_on_free_dynamic_dns: 'Linux ELF File on Free Dynamic DNS',
  is_linux_elf_file_on_free_hosting: 'Linux ELF File on Free Hosting',
  is_linux_elf_file_on_ipv4: 'Linux ELF File on IPv4 Address',
  is_masked_linux_elf_file: 'Masked Linux ELF File Detected',
  is_masked_windows_exe_file: 'Masked Windows Executable Detected',
  is_ms_office_file: 'Microsoft Office File Detected',
  is_windows_exe_file_on_free_dynamic_dns: 'Windows Executable on Free Dynamic DNS',
  is_windows_exe_file_on_free_hosting: 'Windows Executable on Free Hosting',
  is_windows_exe_file_on_ipv4: 'Windows Executable on IPv4 Address',
  is_windows_exe_file: 'Windows Executable Detected',
  is_android_apk_file_on_free_dynamic_dns: 'Android APK on Free Dynamic DNS',
  is_android_apk_file_on_free_hosting: 'Android APK on Free Hosting',
  is_android_apk_file_on_ipv4: 'Android APK on IPv4 Address',
  is_android_apk_file: 'Android APK Detected',
  is_external_redirect: 'External Redirect Detected',
  is_risky_category: 'Risky Category Detected',
  is_domain_recent: 'Domain Recently Created',
  is_domain_very_recent: 'Domain Very Recently Created',
  is_credit_card_field: 'Credit Card Field Present',
  is_password_field: 'Password Field Present',
  is_valid_https: 'Valid HTTPS Connection'
};
const passFailLogic: {[key: string]: boolean | string} = {
      // True means the check needs to be true to pass
    is_valid_https: true,
    is_host_an_ipv4: false,
    is_uncommon_host_length: false,
    is_uncommon_dash_char_count: false,
    is_uncommon_dot_char_count: false,
    is_uncommon_host_name: false,
    is_suspicious_url_pattern: false,
    is_suspicious_file_extension: false,
    is_robots_noindex: false,
    is_suspended_page: false,
    is_most_abused_tld: false,
    is_uncommon_clickable_url: false,
    is_phishing_heuristic: false,
    is_possible_emotet: false,
    is_redirect_to_search_engine: false,
    is_redirect_to_wikipedia: false,
    is_http_status_error: false,
    is_http_server_error: false,
    is_http_client_error: false,
    is_suspicious_content: false,
    is_url_accessible: true,
    is_empty_page_title: false,
    is_empty_page_content: false,
    is_domain_ipv4_assigned: true,
    is_domain_ipv4_private: false,
    is_domain_ipv4_loopback: false,
    is_domain_ipv4_reserved: false,
    is_domain_ipv4_valid: true,
    is_domain_blacklisted: false,
    is_suspicious_domain: false,
    is_sinkholed_domain: false,
    is_defaced_heuristic: false,
    is_masked_file: false,
    is_risky_geo_location: false,
    is_china_country: false,
    is_nigeria_country: false,
    is_non_standard_port: false,
    is_email_address_on_url_query: false,
    is_directory_listing: false,
    is_exe_on_directory_listing: false,
    is_zip_on_directory_listing: false,
    is_php_on_directory_listing: false,
    is_doc_on_directory_listing: false,
    is_pdf_on_directory_listing: false,
    is_apk_on_directory_listing: false,
    is_linux_elf_file: false,
    is_linux_elf_file_on_free_dynamic_dns: false,
    is_linux_elf_file_on_free_hosting: false,
    is_linux_elf_file_on_ipv4: false,
    is_masked_linux_elf_file: false,
    is_masked_windows_exe_file: false,
    is_ms_office_file: false,
    is_windows_exe_file_on_free_dynamic_dns: false,
    is_windows_exe_file_on_free_hosting: false,
    is_windows_exe_file_on_ipv4: false,
    is_windows_exe_file: false,
    is_android_apk_file_on_free_dynamic_dns: false,
    is_android_apk_file_on_free_hosting: false,
    is_android_apk_file_on_ipv4: false,
    is_android_apk_file: false,
    is_external_redirect: false,
    is_risky_category: false,
    is_domain_recent: "no",
    is_domain_very_recent: "no",
    is_credit_card_field: false,
    is_password_field: false,
};

export const analyzeSecurityChecks = (checks: { [key: string]: boolean | string }) => {
  
  let passedChecks = [];
  let failedChecks = [];
  for (const [check, value] of Object.entries(checks)) {
      let shouldPass = passFailLogic.hasOwnProperty(check) ? passFailLogic[check] : false;
      let actualPass = (value === shouldPass) || (shouldPass === true && value !== "no");

      if (actualPass) {
          passedChecks.push(securityCheckMapping[check]);
      } else {
          failedChecks.push(securityCheckMapping[check]);
      }
  }
  return { passedChecks, failedChecks };
}
