/*
 * 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 { workflow } from '../workflow-generator.js';
export function generateReleaseManagerWorkflows(version) {
    return {
        'release-checklist.md': workflow(version, 'Release Checklist', `
## Pre-Deploy Checklist

Before executing any deployment to production:

- [ ] Validation passed in target org (job id recorded below)
- [ ] QA gate approved: all acceptance criteria verified
- [ ] No open P0/P1 blockers in \`.setup-agents/state/\`
- [ ] Stakeholder sign-off obtained (or delegated)
- [ ] Rollback path documented (see Rollback section below)
- [ ] Deployment window confirmed (maintenance window if required)

## Step 1 — Validate

\`\`\`bash
sf project deploy validate -d force-app --target-org <alias> --test-level RunLocalTests
# Record the job ID for quick deploy
\`\`\`

**Validation Job ID:** _______________________

## Step 2 — Quick Deploy

\`\`\`bash
# Use quick deploy if validation succeeded within the last 10 days
sf project deploy quick --job-id <validationJobId> --target-org <alias>

# Full deploy if quick deploy is unavailable
sf project deploy start -d force-app --target-org <alias>
\`\`\`

## Step 3 — Smoke Tests

Run post-deploy smoke tests:
- [ ] Critical user flows verified in production
- [ ] No errors in Salesforce debug logs for 15 minutes post-deploy
- [ ] Monitoring dashboards show no anomalies

## Rollback Decision Tree

> Salesforce has no native rollback. Use compensating transactions.

1. **If deploy failed mid-way:** Check \`sf project deploy report\` for partial state.
2. **If data was corrupted:** Restore from sandbox snapshot or Data Loader backup (pre-deploy export required).
3. **If functionality is broken post-deploy:** Deactivate triggers/flows via Setup, revert metadata from VCS, redeploy previous commit.

## Record Evidence

\`\`\`bash
sf setup-agents evidence add --task <id> --role release-manager --type command --summary "Deployed to <org>: <jobId>"
\`\`\`
`),
        'sandbox-refresh.md': workflow(version, 'Sandbox Refresh Protocol', `
## 1. Pre-Refresh Checklist

- [ ] Export any data that must be preserved (Data Loader or Data Export)
- [ ] Document active integrations and their credentials
- [ ] Notify team of refresh window (no commits during refresh)
- [ ] Confirm data mask template is up-to-date for PII fields

## 2. Refresh Steps

\`\`\`bash
# Identify sandbox name
sf org list sandboxes --target-org <productionAlias>

# Initiate refresh (Setup UI recommended for large sandboxes)
# Salesforce CLI: sandbox refresh available via Setup or API
\`\`\`

## 3. Post-Refresh Validation

- [ ] Deploy latest metadata from VCS:
  \`\`\`bash
  sf project deploy start -d force-app --target-org <sandboxAlias>
  \`\`\`
- [ ] Run smoke tests
- [ ] Restore integration credentials (never stored in VCS)
- [ ] Verify data mask applied (no real PII visible)

## 4. Record Evidence

\`\`\`bash
sf setup-agents evidence add --task <id> --role release-manager --type command --summary "Sandbox <name> refreshed and validated"
\`\`\`
`),
    };
}
//# sourceMappingURL=release-manager.js.map