// IDE folder map — where SKILLS go (techniques, exploits, tools)
const IDE_SKILL_FOLDERS = {
  agents: '.agents/skills',
  claude: '.claude/skills',
  trae:   '.trae/skills',
  codex:  '.codex/skills',
};

// IDE folder map — where AGENTS go (personas, 7 main agents)
// Installed one level up so they're easy to spot and always accessible
const IDE_AGENT_FOLDERS = {
  agents: '.agents',
  claude: '.claude',
  trae:   '.trae',
  codex:  '.codex',
};

/**
 * @param {string[]} ides
 * @param {Set<string>|null} allowedSkills — if null, install everything
 */
function getInstallEntries(ides = ['agents'], allowedSkills = null) {
  // Skills entries — rt-* (non-agent) → .agents/skills/
  const skillEntries = ides.map((ide) => ({
    type: 'glob-dir-prefix',
    base: 'packaged-assets/.agents/skills',
    targetBase: IDE_SKILL_FOLDERS[ide] || `.${ide}/skills`,
    prefix: 'rt-',
    excludePrefix: 'rt-agent-',   // agents go to their own folder
    allowedSkills,
  }));

  // Agent entries — rt-agent-* → .agents/ (root, always visible)
  const agentEntries = ides.map((ide) => ({
    type: 'glob-dir-prefix',
    base: 'packaged-assets/.agents/agents',
    targetBase: IDE_AGENT_FOLDERS[ide] || `.${ide}`,
    prefix: 'rt-agent-',
    allowedSkills,
  }));

  return [
    ...agentEntries,
    ...skillEntries,
    // Master integration files — single source of truth for all agents (Step 0.5).
    // Each IDE folder gets its own copy so any IDE can reference them locally.
    ...ides.flatMap((ide) => {
      const targetBase = IDE_SKILL_FOLDERS[ide] || `.${ide}/skills`;
      return [
        { type: 'path', value: 'packaged-assets/.agents/skills/AGENT-INSTRUCTIONS.md',  target: `${targetBase}/AGENT-INSTRUCTIONS.md`  },
        { type: 'path', value: 'packaged-assets/.agents/skills/AGENT-MEMORY.md',        target: `${targetBase}/AGENT-MEMORY.md`        },
        { type: 'path', value: 'packaged-assets/.agents/skills/END-TO-END-ENGAGEMENT.md', target: `${targetBase}/END-TO-END-ENGAGEMENT.md` },
        { type: 'path', value: 'packaged-assets/.agents/skills/MASTER-CHECKLIST.md',    target: `${targetBase}/MASTER-CHECKLIST.md`    },
        { type: 'path', value: 'packaged-assets/.agents/skills/MASTER-PROMPT.md',        target: `${targetBase}/MASTER-PROMPT.md`        },
        { type: 'path', value: 'packaged-assets/.agents/skills/SCENARIOS-MASTER.md',     target: `${targetBase}/SCENARIOS-MASTER.md`     },
        { type: 'path', value: 'packaged-assets/.agents/skills/SOURCES-MASTER.md',       target: `${targetBase}/SOURCES-MASTER.md`       },
        { type: 'path', value: 'packaged-assets/.agents/skills/TOOLS-MASTER.md',         target: `${targetBase}/TOOLS-MASTER.md`         },
      ];
    }),
    { type: 'path', value: 'packaged-assets/_rtexit',    target: '_rtexit'    },
    { type: 'path', value: 'packaged-assets/templates',  target: 'templates'  },
    { type: 'path', value: 'packaged-assets/resources',  target: 'resources'  },
    { type: 'path', value: 'packaged-assets/RTEXIT.md',  target: 'RTEXIT.md'  },
    { type: 'path', value: 'packaged-assets/docker',     target: 'docker'     },
  ];
}

module.exports = { getInstallEntries };
