/*
 * 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 { existsSync } from 'node:fs';
import { join } from 'node:path';
import { generateReleaseManagerWorkflows } from '../generators/workflows/release-manager.js';
import { codebaseContextualization, consultativeDesign, documentationStandards, generatedPromptsProtocol, getSharedSectionLines, interactionPreferences, salesforceReferences, semanticCommits, } from './shared-sections.js';
export const releaseManagerProfile = {
    id: 'release-manager',
    label: 'Release Manager',
    ruleFile: 'release-manager-standards.mdc',
    extensions: ['github.vscode-github-actions', 'redhat.vscode-yaml'],
    capabilities: ['deploy', 'declare-points'],
    cursorScope: 'auto-attach',
    globs: ['sfdx-project.json', 'package.xml', '.github/workflows/**', 'force-app/**'],
    detect(cwd) {
        return (existsSync(join(cwd, 'sfdx-project.json')) || existsSync(join(cwd, 'force-app')) || existsSync(join(cwd, '.sfdx')));
    },
    workflows: generateReleaseManagerWorkflows,
    ruleContent() {
        return [
            '---',
            'description: Release Manager Standards',
            'globs:',
            'alwaysApply: true',
            '---',
            '',
            '# Release Manager Standards',
            '',
            '> Role: Release Manager — Salesforce Professional Services.',
            '> Complements `devops` (CI/CD infrastructure) — this profile owns the human release process: validate, promote, and communicate.',
            '',
            ...codebaseContextualization('existing deployment scripts, validation history, and org configuration'),
            '',
            ...consultativeDesign('deployment strategy and rollback plan decisions'),
            '',
            '## Deployment Policy (CRITICAL)',
            '- **Always validate before deploying:** `sf project deploy validate -d force-app --target-org <alias> --test-level RunLocalTests`',
            '- **Quick deploy only after successful validation:** `sf project deploy quick --job-id <validationJobId> --target-org <alias>`',
            '- Full deploy is the fallback — only when quick deploy is unavailable (>10 days since validation).',
            '- Never deploy directly to production without QA gate approval and a recorded validation job ID.',
            '',
            '## Sandbox Promotion Sequence',
            '- Dev → Integration → UAT → Staging → Production',
            '- Each promotion requires a passing validation in the target org.',
            '- Sandbox refresh requires pre-refresh data export and data mask application (no PII in non-prod).',
            '',
            '## Rollback Protocol',
            '> Salesforce has no native rollback. The following are compensating strategies:',
            '1. **Failed deploy:** Check `sf project deploy report` — fix conflicts and redeploy.',
            '2. **Broken functionality:** Deactivate triggers/flows via Setup immediately, then redeploy previous VCS commit.',
            '3. **Data corruption:** Restore from pre-deploy Data Loader export. Escalate to backup restore if volume is large.',
            '4. **Always document the incident:** Root cause, duration, impacted users, remediation steps.',
            '',
            '## Release Communication',
            '- Pre-deploy: notify stakeholders of deployment window and expected downtime.',
            '- Post-deploy: confirm success, smoke test results, and any known limitations.',
            '- Use Custom Labels and release notes in `docs/releases/` — never inline in commit messages.',
            '',
            '## Change Set vs Source-Based Deployment',
            '| Criterion | Change Set | Source (sfdx) |',
            '|-----------|------------|--------------|',
            '| Version control | No | Yes (recommended) |',
            '| Partial deploy | Limited | Granular |',
            '| Rollback | Manual | Via VCS |',
            '| CI/CD integration | No | Yes |',
            '- **Prefer source-based deployment** for all new projects.',
            '- Change sets: only for orgs without sfdx-project.json or legacy declarative-only teams.',
            '',
            ...documentationStandards(),
            '',
            ...semanticCommits(),
            '',
            ...generatedPromptsProtocol(),
            '',
            ...salesforceReferences(),
            ...getSharedSectionLines('release-manager'),
            '',
            ...interactionPreferences(),
        ].join('\n');
    },
};
//# sourceMappingURL=release-manager.js.map