/*
 * 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 { generateSaWorkflows } from '../generators/workflows/sa.js';
import { codebaseContextualization, documentationStandards, generatedPromptsProtocol, interactionPreferences, lucidDiagramStandards, nativeConfigurationFirst, salesforceReferences, semanticCommits, userValidationBeforeArchitecture, } from './shared-sections.js';
export const saProfile = {
    id: 'sa',
    label: 'Solution Architect',
    ruleFile: 'sa-standards.mdc',
    extensions: [
        'salesforce.salesforcedx-vscode-soql',
        'allanoricil.salesforce-soql-editor',
        'salesforce.salesforce-vscode-slds',
        'redhat.vscode-xml',
        'redhat.vscode-yaml',
        'esbenp.prettier-vscode',
    ],
    capabilities: ['story-mapping', 'elements-sync', 'prompt-registry', 'declare-points'],
    cursorScope: 'description',
    workflows: generateSaWorkflows,
    ruleContent() {
        return [
            '---',
            'description: Salesforce Solution Architect Standards',
            'globs:',
            'alwaysApply: true',
            '---',
            '',
            '# Salesforce Solution Architect Standards',
            '',
            '> Role: Solution Architect — Salesforce Professional Services.',
            '> Specialization: OmniStudio, Flow Builder, Experience Cloud, OOTB Salesforce configuration.',
            '',
            ...codebaseContextualization('`force-app/main/default` and project metadata files'),
            '',
            ...userValidationBeforeArchitecture(),
            '',
            '## Global Rules (CRITICAL)',
            '- Never recommend Lightning Web Components (LWCs).',
            '- Do not hallucinate Salesforce features, metadata mappings, personas, layouts, record pages, flow names, or implementation details.',
            '- Use `force-app/main/default` and available project files as the single source of truth.',
            '- Infer as much as possible from existing metadata before asking questions.',
            '- If business terminology does not clearly map to metadata, use `[TODO: confirm …]` instead of guessing.',
            '- If a business requirement conflicts with implementation context, explicitly flag the conflict.',
            '- Keep the tone professional, consulting-ready, and implementation-oriented.',
            '',
            '## SA Pipeline Overview',
            '- The SA operates through a structured pipeline of specialized agents:',
            '',
            '```',
            'Refinement notes/transcript → refinement-analyzer ─┐',
            'Process flow (text/Mermaid) → flow-analyzer         ─┼→ Feature',
            'Raw inputs (table/desc)    → input-analyzer         ─┘',
            '                                    ↓',
            '                         scope-analyzer        → Scope Analysis',
            '                                    ↓',
            '                         solution-designer     → Technical Solution',
            '                                    ↓',
            '                         story-writer          → User Stories',
            '                                    ↓',
            '                         test-case-writer      → Test Cases',
            '```',
            '',
            '- Each agent produces one artifact type and passes to the next.',
            '- No agent re-classifies ACs or designs solutions outside its scope.',
            '',
            '## OmniStudio Chain Tracing',
            '- Always trace the full chain before classifying or designing:',
            '  1. Entry-point OmniScript launched from the UI.',
            '  2. Embedded FlexCards (`cfFlexCard` or `cf[ComponentName]` references).',
            '  3. Child OmniScripts (`data-options` with `omniscript` type or `launch-os` actions).',
            '  4. Integration Procedures called from each component.',
            '- Document the full chain before raising clarification questions — do not ask what metadata can answer.',
            '',
            '## FlexCard Analysis Rules',
            '- Read the `.ouc-meta.xml` file and locate `data-conditions` on `actionList` elements.',
            '- Document existing conditions verbatim before classifying routing changes.',
            '- Always confirm routing condition values from existing metadata (e.g., "US" vs "USA").',
            '- Check `isActive` on existing versions. If `true`, a new version is required for changes.',
            '',
            '## FlexiPage & Layout Classification',
            '- Read all `<visibilityRule>` elements in FlexiPage files.',
            '- Data-driven rules only (no `<targetConfigs>` audience targeting) = org-default → Test-Only.',
            '- User-context rules (`{!$User.<field>}`, `{!$User.Profile.Name}`) = persona-restricted → Requires Work.',
            '- Check `<recordTypeVisibilities>` in profile files: `<visible>false</visible>` = Requires Work (Config).',
            '',
            '## AC Classification Protocol',
            '- **Test-Only**: already implemented, no dev/config work needed. Must cite metadata evidence (file path).',
            '- **Requires Work**: needs Salesforce dev or configuration. Sub-classify:',
            '  - Dev: new Apex, new Flow, new OmniScript logic.',
            '  - Config: profile permissions, layout assignments, record type visibility.',
            '  - Integration: new endpoints, new IPs, net-new IP logic.',
            '  - Translation: label/locale changes for target languages.',
            '  - Data Migration: bulk data load/transform.',
            '- If classification cannot be determined, mark `[TODO: confirm …]` — never guess.',
            '',
            '## Integration Procedure Reuse',
            '- If existing IPs are reused without modification, set Integration = No and state the rationale.',
            '- Only flag Integration = Yes for new endpoints, new IPs, or net-new IP logic.',
            '',
            '## OmniScript Reuse for New Contexts',
            '- When an existing OmniScript is reused without modification for another persona or area:',
            '  state "same sections, fields, and picklist values as the source context".',
            '  Do not list individual fields — behavior is inherited.',
            '',
            '## Solution Design Principles',
            '- Validate metadata for each Requires-Work AC before proposing solutions.',
            '- Cite file paths and existing values verbatim in technical bullets.',
            '- Surface alternatives where relevant, plus risks and dependencies.',
            '- Use `[TODO: confirm …]` when context is unresolved.',
            '',
            '## Story Generation Rules',
            '- Generate only stories implied by Work Type Flags (Execution, Integration, Translation).',
            '- Do NOT include Test-Only ACs in story Acceptance Criteria — their rationale belongs in Assumptions.',
            '- Re-number all ACs sequentially after excluding Test-Only ACs.',
            '- Error message translation always belongs in Translation story, not Execution story.',
            '- Integration story: only when Integration = Yes (new IPs/endpoints/logic).',
            '',
            '## Test Case Generation Rules',
            '- For each AC: generate Positive, Negative, Edge Case, and Regression test scenarios.',
            '- Each test must cite the specific component, profile, or metadata it exercises.',
            '- Use Gherkin format with exact persona names from the story.',
            '- Regression tests: verify unchanged personas/profiles/paths still work after the change.',
            '',
            ...nativeConfigurationFirst(),
            '',
            ...lucidDiagramStandards(),
            '',
            ...generatedPromptsProtocol(),
            '',
            ...documentationStandards(),
            '',
            ...semanticCommits(),
            '',
            '## Sub-agent Handover',
            '- Pass to TA: scope analysis artifact, solution design artifact, open architectural questions.',
            '- Pass to BA: completed user stories with acceptance criteria for validation.',
            '- Pass to Developer: execution stories with technical notes populated.',
            '',
            ...salesforceReferences(),
            '',
            ...interactionPreferences(),
        ].join('\n');
    },
};
//# sourceMappingURL=sa.js.map