/*
 * 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 { getSharedSectionLines } from './shared-sections.js';
export const salesCloudProfile = {
    id: 'salescloud',
    label: 'Sales Cloud',
    ruleFile: 'salescloud-standards.mdc',
    extensions: ['salesforce.salesforcedx-vscode'],
    capabilities: ['deploy', 'code-analysis', 'prompt-registry', 'declare-points'],
    cursorScope: 'description',
    detect(cwd) {
        return (existsSync(join(cwd, 'force-app/main/default/objects/Opportunity')) ||
            existsSync(join(cwd, 'force-app/main/default/objects/Lead')) ||
            existsSync(join(cwd, 'force-app/main/default/objects/Quote')) ||
            existsSync(join(cwd, 'force-app/main/default/territory2Models')));
    },
    ruleContent() {
        return [
            '---',
            'description: Salesforce Sales Cloud Standards',
            'globs: force-app/**/*.{cls,trigger,js,html,xml}',
            '---',
            '',
            '# Sales Cloud Standards',
            '',
            '## Lead Management',
            '- **Lead assignment rules:** use Assignment Rules or lead routing (Salesforce Flow) over Apex triggers for round-robin and territory-based assignment.',
            '- **Lead conversion:** always map Lead fields to Account/Contact/Opportunity during conversion. Use `Database.convertLead()` with `LeadConvert` settings.',
            '- **Web-to-Lead:** validate and deduplicate incoming leads before insertion. Consider duplicate rules + matching rules.',
            '- **Lead scoring:** implement via Flow or Process Builder with custom fields (Score__c). Avoid Apex for simple scoring logic.',
            '',
            '## Opportunity Management',
            '- **Sales stages:** map to `StageName` picklist values. Each stage should have defined exit criteria and probability.',
            '- **Opportunity products:** use `OpportunityLineItem` with `PricebookEntry`. Never hardcode prices in Apex — always reference Price Books.',
            '- **Close date management:** use validation rules to prevent past close dates on open opportunities.',
            '- **Big Deal alerts:** use Flow-based notifications for opportunities above threshold amounts.',
            '- **Opportunity splits:** configure team selling with `OpportunitySplit` when revenue sharing is needed.',
            '',
            '## Forecasting',
            '- **Forecast categories:** align with opportunity stages (Pipeline, Best Case, Commit, Closed).',
            '- **Collaborative forecasting:** use `ForecastingAdjustment` for manager overrides.',
            '- **Custom forecast types:** define by role, territory, or product family as needed.',
            '- **Quota management:** use `ForecastingQuota` objects. Bulk load via Data Loader for quarterly resets.',
            '',
            '## Territory Management',
            '- **Territory2 model:** activate Enterprise Territory Management. Define territory hierarchy.',
            '- **Territory assignment rules:** use `ObjectTerritory2Association` for account-territory mapping.',
            '- **Territory-based sharing:** configure sharing rules that grant access based on territory membership.',
            '- **User-territory association:** manage via `UserTerritory2Association`. One user can belong to multiple territories.',
            '',
            '## Products, Price Books & Quotes',
            '- **Product catalog:** use `Product2` with `IsActive` flag. Organize by `Family` picklist.',
            '- **Price Books:** use standard + custom price books. Never bypass PricebookEntry for pricing.',
            '- **Quotes:** use `Quote` object with `QuoteLineItem`. Sync selected quote to opportunity.',
            '- **Discount approval:** implement via approval process on Quote when discount exceeds threshold.',
            '- **CPQ integration:** if Salesforce CPQ is present, defer to CPQ profile rules.',
            '',
            '## Sales Processes & Automation',
            '- **Sales processes:** define per record type to control available stages.',
            '- **Path (Guidance for Success):** configure key fields and guidance per stage for user adoption.',
            '- **Einstein Activity Capture:** enable for automatic email/event logging. Respect privacy settings.',
            '- **Cadences (Sales Engagement):** use for outreach sequences. Track step completion.',
            '- **Approval processes:** use for discount approvals, contract sign-off. Chain approvers by role.',
            '',
            '## Reporting & Analytics',
            '- **Pipeline reports:** group by stage, owner, territory. Include weighted amount.',
            '- **Win/loss analysis:** track `StageName` history via `OpportunityFieldHistory`.',
            '- **Activity metrics:** report on tasks/events per opportunity for coaching.',
            '- **Dashboard best practices:** one dashboard per role (rep, manager, VP).',
            '',
            ...getSharedSectionLines('salescloud'),
        ].join('\n');
    },
};
//# sourceMappingURL=salescloud.js.map