/*
 * 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 generateFscWorkflows(version) {
    return {
        'financial-account-setup.md': workflow(version, 'Financial Account Setup', `
## 1. Gather Requirements

Ask:
- **Account model:** Are clients individuals (PersonAccount) or businesses (Business Account)? Mixed?
- **Household model:** Do related individuals need to be grouped under a Household Account?
- **Financial account types:** Checking, Savings, Investment, Insurance, Mortgage, Loan — which apply?
- **Ownership roles:** Who are the primary owner, joint owners, and beneficiaries for each financial account?
- **Rollup requirements:** Does the household or client record need aggregated balance/value rollups?

Check \`force-app/main/default/objects/\` for existing \`FinServ__FinancialAccount__c\` field customizations before adding new fields.

## 2. Configure the Data Model

### PersonAccount vs Business Account
- Enable PersonAccount in Setup → Account Settings if individual clients are needed.
- Use a dedicated PersonAccount Record Type for retail clients (e.g., \`Individual_Client\`).
- Business Accounts represent institutions, employers, or corporate clients.
- Never mix PersonAccount and Business Account in the same Record Type — separate page layouts.

### Household Account
- A Household is a standard Account with Record Type \`IndustriesHousehold\` (FSC-managed).
- Link members via \`FinServ__ContactContactRelation__c\` (Reciprocal Roles).
- Set \`FinServ__PrimaryGroup__c\` on Contact to point to the Household Account.
- One Contact can belong to multiple groups — but only one primary group.

### Financial Account Record Types
Map business financial account types to FSC Record Types on \`FinServ__FinancialAccount__c\`:
- Savings / Checking → \`BankAccount\`
- Investment / Brokerage → \`InvestmentAccount\`
- Insurance Policy → \`InsurancePolicy\`
- Mortgage / Loan → \`CreditFacility\`
- Each Record Type drives a distinct page layout and field visibility.

## 3. Set Up Ownership Roles

1. Navigate to Setup → Financial Services → Financial Account Roles.
2. Define role types: Primary Owner, Joint Owner, Beneficiary, Power of Attorney, Trustee.
3. Create \`FinServ__FinancialAccountRole__c\` records linking the financial account to each Contact.
4. Set \`FinServ__Role__c\` picklist value per role type.
5. Verify \`FinServ__PrimaryOwner__c\` lookup on the Financial Account points to the primary Contact.

## 4. Configure Rollup Summaries

FSC uses Custom Metadata Type \`FinServ__RollupByLookupConfig__mdt\` for cross-object rollups:

1. Go to Setup → Custom Metadata Types → Rollup By Lookup Config → Manage Records.
2. Create a new record:
   - **Source Object:** \`FinServ__FinancialAccount__c\`
   - **Source Field:** \`FinServ__Balance__c\`
   - **Target Object:** \`Account\` (Household)
   - **Target Field:** \`FinServ__TotalAssets__c\`
   - **Lookup Field:** \`FinServ__PrimaryGroup__c\`
   - **Operation:** SUM
3. Rollups execute via the FSC Rollup Trigger on \`FinServ__FinancialAccount__c\` — do NOT add additional triggers on this object without reviewing governor limit impact.

## 5. Deploy Financial Account Metadata

\`\`\`bash
sf project deploy start \\
  --source-dir force-app/main/default/objects/FinServ__FinancialAccount__c \\
  --source-dir force-app/main/default/customMetadata \\
  --target-org <alias>
\`\`\`

Verify in the target org:
- Financial Account Record Types visible under the correct Account
- Rollup values update after saving a Financial Account record
- Ownership roles display on the Financial Account related list
`),
        'arc-configuration.md': workflow(version, 'Actionable Relationship Center (ARC) Configuration', `
## 1. Understand ARC Architecture

ARC is the FSC relationship visualization and management layer, replacing the legacy Relationship Viewer.

Key concepts:
- **Relationship Groups:** Sets of related records displayed as nodes in the ARC graph (e.g., Household members, business owners, beneficiaries).
- **Cards:** Record types rendered as visual nodes. Each card maps to an object + record type.
- **Actions:** Context-sensitive quick actions available from ARC nodes (e.g., create referral, log call).
- **Display Categories:** Control which relationship types appear in the graph and in which grouping panel.

## 2. Plan the Relationship Map

Ask before configuring:
- Which objects should appear as nodes? (Contact, Account, Financial Account, Opportunity, Insurance Policy)
- What relationships should be traversable? (Household membership, ownership roles, reciprocal roles)
- Which actions should be available per node type?
- Are there compliance restrictions on what relationship data can be displayed to specific roles?

## 3. Configure ARC in Setup

Navigate to: Setup → Financial Services → Actionable Relationship Center

### Cards Setup
1. Create a Card for each object to display (e.g., Contact Card, Financial Account Card).
2. Set the **Object** and **Record Type** for each card.
3. Assign **Display Fields** — the fields shown on the card node (max 4 recommended for readability).
4. Configure **Card Actions** — which quick actions appear in the action menu on the node.

### Groups Setup
1. Define Groups to represent relationship categories (e.g., "Household Members", "Business Owners").
2. Set the **Relationship Field** — the lookup field on the related object pointing to the root record.
3. Assign the **Card** to use for records in this group.
4. Set **Cardinality**: One-to-One vs. One-to-Many (controls display layout).

### Display Categories
1. Create Display Categories to organize groups in the left panel of the ARC component.
2. Assign Groups to Categories.
3. Set the order of categories for display priority.

## 4. Assign ARC to Lightning Pages

1. Open Lightning App Builder for the Account or Contact page.
2. Add the **Actionable Relationship Center** standard component.
3. Set the **ARC Configuration** property to the configuration created above.
4. Restrict visibility by Profile or Permission Set if different user roles need different graph views.

## 5. Configure Reciprocal Roles

Reciprocal Roles define the relationship labels shown in the ARC graph:
1. Navigate to Setup → Financial Services → Reciprocal Roles.
2. Create role pairs: e.g., "Spouse" ↔ "Spouse", "Parent" ↔ "Child", "Employer" ↔ "Employee".
3. Roles appear as edge labels between nodes in the relationship graph.
4. Use \`FinServ__ContactContactRelation__c\` records to instantiate role relationships between Contacts.

## 6. Test ARC
- Open a Household Account record and verify the graph renders all expected member nodes.
- Confirm actions are available and trigger the correct flows or quick actions.
- Test with a user in a restricted profile to verify Display Category access controls.
`),
        'referral-management.md': workflow(version, 'Referral Management Setup', `
## 1. Gather Requirements

Ask:
- **Referral source:** Internal (advisor to advisor) or external (client to client)?
- **Referral stages:** What lifecycle stages does a referral go through? (New, Contacted, Converted, Lost)
- **Conversion target:** Does a referral convert to a Lead, Opportunity, or directly to a Financial Account?
- **Attribution:** How is referral credit tracked for compensation or reporting?
- **Notification rules:** Who gets notified when a referral is created or accepted?

## 2. Configure the Referral Object

\`FinServ__Referral__c\` is the core FSC referral object.

Key fields:
- \`FinServ__ReferredBy__c\` (Lookup to User) — the advisor making the referral
- \`FinServ__ReferredTo__c\` (Lookup to User) — the receiving advisor
- \`FinServ__Account__c\` (Lookup to Account) — the client being referred
- \`FinServ__Status__c\` (Picklist) — lifecycle stage
- \`FinServ__ConvertedOpportunity__c\` (Lookup to Opportunity) — populated on conversion

Customize picklist values for \`FinServ__Status__c\` to match the business process.
Do NOT delete FSC-managed fields — extend only.

## 3. Automate Referral Lifecycle

Use Record-Triggered Flows (never triggers directly on FSC managed objects unless documented):

### On Referral Creation (Before Save)
- Validate \`ReferredBy\` ≠ \`ReferredTo\` (an advisor cannot refer to themselves).
- Set default \`Status\` = "New" if blank.

### On Status Change to "Accepted" (After Save)
- Send email alert to the receiving advisor.
- Create a Task for follow-up with due date = Today + 3 business days.

### On Status Change to "Converted" (After Save)
- Create or update the related Opportunity.
- Populate \`FinServ__ConvertedOpportunity__c\` lookup.
- Log a completed Activity on the client Account.

## 4. Referral Scoring (Optional — Einstein Next Best Action)
- Define a Recommendation Strategy using Salesforce Flow and Einstein NBA.
- Score inbound referral candidates based on: AUM, product ownership gaps, life events.
- Surface recommendations on the Advisor homepage via the Einstein Next Best Action component.

## 5. Deploy Referral Configuration

\`\`\`bash
sf project deploy start \\
  --source-dir force-app/main/default/objects/FinServ__Referral__c \\
  --source-dir force-app/main/default/flows/<ReferralFlowApiName>.flow-meta.xml \\
  --target-org <alias>
\`\`\`
`),
    };
}
//# sourceMappingURL=fsc.js.map