/*
 * Copyright 2026, Jaime Terrats.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import { join } from 'node:path';
import { ensureDir } from '../services/file-writer.js';
import { stripMdcFrontmatter } from '../generators/shared.js';
import { PLUGIN_VERSION } from '../version.js';
/**
 * Generates prompt files for JetBrains AI Assistant under `.idea/ai-prompts/`.
 *
 * JetBrains AI Assistant reads `.md` files from `.idea/ai-prompts/` as
 * persistent context prompts. Each profile gets its own file; a shared
 * `setup-agents-guidelines.md` covers cross-cutting standards.
 */
export function setupJetBrains(opts) {
    const { cwd, profiles, writer } = opts;
    const promptsDir = join(cwd, '.idea', 'ai-prompts');
    ensureDir(promptsDir);
    const header = `<!-- setup-agents: ${PLUGIN_VERSION} -->`;
    const guidelinesContent = [
        header,
        '',
        '# Setup Agents — General Guidelines',
        '',
        '## General Principles',
        '- Always read existing code before suggesting changes.',
        '- Prefer editing existing files over creating new ones.',
        '- Follow the coding conventions already present in this project.',
        '- Write concise, self-documenting code. Avoid unnecessary comments.',
        '',
        '## Code Quality',
        '- Ensure all new code is covered by tests.',
        '- Do not introduce linter errors or suppress warnings.',
        '- Handle errors explicitly; never swallow exceptions silently.',
        '',
        '## Security',
        '- Never hardcode credentials, tokens, or sensitive data.',
        '- Use environment variables or secret managers for sensitive values.',
    ].join('\n');
    writer.write(join(promptsDir, 'setup-agents-guidelines.md'), guidelinesContent);
    for (const profile of profiles) {
        const body = stripMdcFrontmatter(profile.ruleContent()).trimStart();
        const content = `${header}\n\n${body}`;
        writer.write(join(promptsDir, `${profile.id}.md`), content);
    }
}
//# sourceMappingURL=jetbrains-setup.js.map