/*
 * 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 { generateExperienceCloudWorkflows } from '../generators/workflows/experience-cloud.js';
import { codebaseContextualization, consultativeDesign, documentationStandards, generatedPromptsProtocol, interactionPreferences, salesforceReferences, semanticCommits, testCoverageStandards, } from './shared-sections.js';
export const experienceCloudProfile = {
    id: 'experience-cloud',
    label: 'Experience Cloud Developer',
    ruleFile: 'experience-cloud-standards.mdc',
    extensions: [
        'salesforce.salesforcedx-vscode',
        'salesforce.salesforcedx-vscode-lwc',
        'salesforce.salesforcedx-vscode-apex',
    ],
    capabilities: ['deploy', 'code-analysis', 'prompt-registry', 'declare-points'],
    cursorScope: 'auto-attach',
    globs: [
        'force-app/main/default/experiences/**',
        'force-app/main/default/sites/**',
        'force-app/main/default/cmsContent/**',
        'force-app/main/default/navigationMenus/**',
        'force-app/main/default/brandingSets/**',
    ],
    detect(cwd) {
        return (existsSync(join(cwd, 'force-app', 'main', 'default', 'experiences')) ||
            existsSync(join(cwd, 'force-app', 'main', 'default', 'sites')));
    },
    workflows: generateExperienceCloudWorkflows,
    ruleContent() {
        return [
            '---',
            'description: Experience Cloud Developer Standards',
            'globs:',
            'alwaysApply: true',
            '---',
            '',
            '# Experience Cloud Developer Standards',
            '',
            '> Role: Experience Cloud Developer — Salesforce Professional Services.',
            '',
            ...codebaseContextualization('existing Experience Cloud sites, LWR/Aura architecture, and guest user security model'),
            '',
            ...consultativeDesign('site architecture and guest user security decisions'),
            '',
            '## LWR vs Aura Architecture',
            '- Identify the site type from `force-app/main/default/experiences/<SiteName>.site-meta.xml`.',
            '- LWR sites: LWC components only, CSS Modules, wire adapters for data, `sf community publish` required after content changes.',
            '- Aura sites: LWC + Aura components, Aura event bus, token-based styling.',
            '- Never mix LWR and Aura architectural patterns in the same site.',
            '',
            '## Guest User Security (CRITICAL)',
            '- **Every SOQL query reachable by guest users must use `WITH USER_MODE` or `Security.stripInaccessible()`.**',
            '- Never expose PII fields through guest-accessible Apex or pages without explicit FLS validation.',
            '- Guest Profile must have the minimum necessary object/field permissions — review after every schema change.',
            '- Apex classes called from guest-accessible controllers: must use `with sharing`. `without sharing` is forbidden.',
            '',
            '## CMS Content and Navigation',
            '- CMS content types live in `force-app/main/default/cmsContent/`.',
            '- Navigation menus are managed via Experience Workspaces (not metadata) — document manual steps.',
            '- Branding sets should reference SLDS design tokens.',
            '',
            '## Deploy and Publish Workflow',
            '- Deploy metadata with `sf project deploy start -d force-app --target-org <alias>`.',
            '- **Always run `sf community publish --name "<SiteName>" --target-org <alias>` after LWR content changes.**',
            '- LWR Site changes are NOT active until published — metadata deploy alone is not sufficient.',
            '',
            '## LWC for Experience Cloud',
            '- Expose components to Experience Builder via `isExposed: true` in `<component>.js-meta.xml`.',
            '- Use `@salesforce/community/basePath` wire adapter for site-relative URL generation.',
            '- Prioritize SLDS Styling Hooks for theming — avoid custom CSS that conflicts with branding sets.',
            '',
            ...testCoverageStandards(),
            '',
            '## Evidence Standards',
            '- After any Experience Cloud deployment or publish: record with `--role experience-cloud --type command`.',
            '',
            ...documentationStandards(),
            '',
            ...semanticCommits(),
            '',
            ...generatedPromptsProtocol(),
            '',
            ...salesforceReferences(),
            '',
            ...interactionPreferences(),
        ].join('\n');
    },
};
//# sourceMappingURL=experience-cloud.js.map