/**
 * Install profiles — each profile maps to a set of skill folder names.
 * Skills in CORE are always installed regardless of profile selection.
 * Users pick one or more profiles; they get CORE + selected profiles.
 */

const CORE = [
  // Agents
  'rt-agent-breaker',
  'rt-agent-commander',
  'rt-agent-ghost',
  'rt-agent-navigator',
  'rt-agent-phantom',
  'rt-agent-scout',
  'rt-agent-scribe',
  // Base methodology
  'rt-help',
  'rt-status',
  'rt-party-mode',
  'rt-scope-definition',
  'rt-rules-of-engagement',
  'rt-methodology-selector',
  // Recon & mapping
  'rt-active-recon',
  'rt-osint',
  'rt-shodan-recon',
  'rt-attack-surface-map',
  'rt-subdomain-enum',
  'rt-subdomain-takeover',
  'rt-wordlist-generation',
  'rt-password-spray',
  // Infrastructure
  'rt-c2-operations',
  'rt-redteam-infra',
  // Core execution
  'rt-defense-evasion',
  'rt-lateral-movement',
  'rt-persistence',
  'rt-post-exploitation',
  'rt-privilege-escalation',
  'rt-credential-access',
  'rt-credential-hunt',
  'rt-lsass-dumping',
  'rt-data-exfiltration',
];

const PROFILES = {
  web: {
    label: 'Web & API',
    description: 'Web apps, APIs, injection, auth, OWASP Top 10',
    skills: [
      'rt-exploit-web',
      'rt-exploit-injection',
      'rt-exploit-xss',
      'rt-exploit-ssrf',
      'rt-exploit-auth',
      'rt-exploit-idor',
      'rt-exploit-api',
      'rt-exploit-jwt',
      'rt-exploit-file-upload',
      'rt-cors-csrf',
      'rt-clickjacking',
      'rt-dom-attacks',
      'rt-cache-attacks',
      'rt-business-logic',
      'rt-race-conditions',
      'rt-request-smuggling',
      'rt-path-traversal',
      'rt-deserialization',
      'rt-prototype-pollution',
      'rt-http-parameter-pollution',
      'rt-ldap-xpath-injection',
      'rt-xxe',
      'rt-oauth-oidc',
      'rt-websockets-grpc',
      'rt-js-analysis',
      'rt-browser-exploitation',
      'rt-exploit-wordpress',
      'rt-exploit-nodejs',
      'rt-exploit-php',
      'rt-exploit-python',
      'rt-exploit-java',
      'rt-exploit-dotnet',
      'rt-exploit-ruby',
      'rt-exploit-frameworks',
      'rt-exploit-electron',
      'rt-exploit-firebase',
      'rt-supabase',
      'rt-exploit-osticket',
      'rt-exploit-bec',
      'rt-serverless',
      'rt-exploit-elasticsearch',
      'rt-exploit-databases',
      'rt-exploit-mongodb',
      'rt-exploit-mssql',
      'rt-exploit-mysql',
      'rt-exploit-postgresql',
      'rt-exploit-redis',
      'rt-ai-llm-security',
      'rt-crypto-attacks',
      'rt-exploit-fuzzing',
      'rt-exploit-graphql',
    ],
  },

  mobile: {
    label: 'Mobile',
    description: 'Android, iOS, BLE, Frida, SSL bypass, cross-platform, C2',
    skills: [
      // Core mobile
      'rt-exploit-android',
      'rt-exploit-ios',
      'rt-bluetooth-ble',
      // Advanced mobile (new)
      'rt-frida-advanced',
      'rt-mobile-ssl-pinning',
      'rt-apk-repackaging',
      'rt-android-intent-exploitation',
      'rt-cross-platform-mobile',
      'rt-mobile-malware-c2',
      'rt-mobile-static-deep',
    ],
  },

  cloud: {
    label: 'Cloud',
    description: 'AWS, Azure, GCP, Kubernetes, containers',
    skills: [
      'rt-exploit-cloud-aws',
      'rt-exploit-cloud-azure',
      'rt-exploit-cloud-gcp',
      'rt-kubernetes',
      'rt-exploit-containers',
      'rt-serverless',
      'rt-supply-chain',
      'rt-exploit-firebase',
      'rt-supabase',
      'rt-exploit-elasticsearch',
    ],
  },

  ad: {
    label: 'Active Directory & Windows',
    description: 'AD, ADCS, Kerberos, lateral movement, EDR bypass, APT techniques',
    skills: [
      'rt-exploit-active-directory',
      'rt-exploit-adcs',
      'rt-adcs-esc9-13',
      'rt-adfs',
      'rt-azure-ad',
      'rt-exchange-sharepoint',
      'rt-exploit-desktop-win',
      'rt-exploit-desktop-mac',
      'rt-printer-attacks',
      'rt-network-segmentation',
      'rt-exploit-network',
      'rt-ssl-mitm',
      'rt-citrix-vdi',
      // Nation-state / APT
      'rt-kerberos-relay',
      'rt-diamond-sapphire-tickets',
      'rt-zerologon',
      'rt-printnightmare-rce',
      'rt-golden-saml',
      'rt-skeleton-key',
      'rt-syscall-bypass',
      'rt-etw-bypass',
      'rt-process-injection-advanced',
      'rt-ppid-spoofing',
      'rt-beacon-sleep-masking',
      'rt-clm-jea-escape',
    ],
  },

  reporting: {
    label: 'Reporting & Documentation',
    description: 'Reports, findings, CVSS, MITRE, scenarios, compliance',
    skills: [
      'rt-technical-report',
      'rt-executive-report',
      'rt-finding-document',
      'rt-finding-tracker',
      'rt-autodoc',
      'rt-create-sead',
      'rt-evidence-chain',
      'rt-compliance-mapper',
      'rt-cvss-calculator',
      'rt-poc-writer',
      'rt-risk-matrix',
      'rt-mitre-map',
      'rt-kill-chain-map',
      'rt-remediation-roadmap',
      'rt-attack-chain-builder',
      'rt-timeline',
      'rt-threat-model',
      'rt-scenario-library',
      'rt-scenario-c001', 'rt-scenario-c002', 'rt-scenario-c003', 'rt-scenario-c004', 'rt-scenario-c005',
      'rt-scenario-d001', 'rt-scenario-d002', 'rt-scenario-d003', 'rt-scenario-d004', 'rt-scenario-d005',
      'rt-scenario-m001', 'rt-scenario-m002', 'rt-scenario-m003', 'rt-scenario-m004', 'rt-scenario-m005',
      'rt-scenario-n001', 'rt-scenario-n002', 'rt-scenario-n003', 'rt-scenario-n004', 'rt-scenario-n005',
      'rt-scenario-w001', 'rt-scenario-w002', 'rt-scenario-w003', 'rt-scenario-w004', 'rt-scenario-w005',
      'rt-scenario-w006', 'rt-scenario-w007', 'rt-scenario-w008', 'rt-scenario-w009', 'rt-scenario-w010',
    ],
  },

  specialist: {
    label: 'Specialist',
    description: 'SCADA/ICS, IoT, hardware, physical, social engineering, wireless, WiFi',
    skills: [
      'rt-exploit-scada',
      'rt-exploit-iot',
      'rt-hardware-hacking',
      'rt-exploit-wireless',
      'rt-wireless-rogue-ap',
      'rt-wifi-attacks',
      'rt-exploit-physical',
      'rt-exploit-phishing',
      'rt-exploit-vishing',
      'rt-social-engineering',
      'rt-voip-sip',
      'rt-traffic-analysis',
      'rt-binary-reverse-engineering',
      'rt-sap-exploitation',
      'rt-steganography',
    ],
  },

  recon: {
    label: 'Recon & OSINT',
    description: 'OSINT, GitHub recon, subdomain enum, attack surface mapping',
    skills: [
      'rt-active-recon',
      'rt-osint',
      'rt-shodan-recon',
      'rt-subdomain-enum',
      'rt-subdomain-takeover',
      'rt-wordlist-generation',
      'rt-attack-surface-map',
      'rt-github-recon',
      'rt-js-analysis',
      'rt-password-spray',
    ],
  },

  devops: {
    label: 'DevOps / IaC',
    description: 'IaC misconfigs, Terraform, K8s YAML, CloudFormation, supply chain',
    skills: [
      'rt-iac-misconfig',
      'rt-supply-chain',
      'rt-kubernetes',
      'rt-exploit-containers',
      'rt-serverless',
      'rt-github-recon',
    ],
  },
};

/**
 * Resolve the full set of skill folder names to install.
 * @param {string[]|'all'} selectedProfiles — array of profile keys or 'all'
 * @returns {Set<string>} — set of skill folder names
 */
function resolveSkillSet(selectedProfiles) {
  if (selectedProfiles === 'all' || (Array.isArray(selectedProfiles) && selectedProfiles.includes('all'))) {
    const all = new Set(CORE);
    for (const profile of Object.values(PROFILES)) {
      for (const s of profile.skills) all.add(s);
    }
    return all;
  }

  const result = new Set(CORE);
  for (const key of selectedProfiles) {
    if (PROFILES[key]) {
      for (const s of PROFILES[key].skills) result.add(s);
    }
  }
  return result;
}

module.exports = { PROFILES, CORE, resolveSkillSet };
