/*
 * 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 { generateEducationWorkflows } from '../generators/workflows/education.js';
import { consultativeDesign, deployment, documentationStandards, flsAndCrudEnforcement, generatedPromptsProtocol, getSharedSectionLines, interactionPreferences, nativeConfigurationFirst, salesforceReferences, semanticCommits, testCoverageStandards, } from './shared-sections.js';
export const educationProfile = {
    id: 'education',
    label: 'Education Cloud',
    ruleFile: 'education-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/hed__Course__c')) ||
            existsSync(join(cwd, 'force-app/main/default/objects/hed__Term__c')) ||
            existsSync(join(cwd, 'force-app/main/default/objects/Application__c')) ||
            existsSync(join(cwd, 'force-app/main/default/objects/ProgramEnrollment')));
    },
    workflows: generateEducationWorkflows,
    ruleContent() {
        return [
            '---',
            'description: Education Cloud (EDA) Standards',
            'globs:',
            'alwaysApply: true',
            '---',
            '',
            '# Education Cloud (EDA) Standards',
            '',
            '> Role: Education Cloud Developer / Consultant — Salesforce Professional Services.',
            '> Education Cloud builds on the Education Data Architecture (EDA) managed package (hed__ namespace). All standards here apply **in addition to** general Apex and LWC rules.',
            '',
            ...consultativeDesign('EDA data model and student lifecycle decisions'),
            '',
            ...nativeConfigurationFirst(),
            '',
            '## EDA Data Model (CRITICAL)',
            '- **Administrative Account Model.** In EDA, Accounts represent institutions (University → College → Department), NOT companies.',
            '  Each Account has a Record Type: `Academic_Program`, `University_Department`, `Educational_Institution`, `Sports_Organization`, etc.',
            '- **Contacts represent people.** Students, staff, faculty, alumni — all are Contacts with different Affiliations.',
            '- **HEDA Hierarchy.** The institutional hierarchy is modeled via Account parent-child relationships:',
            '  University (top) → College → Department → Program. Never flatten this into custom fields.',
            '- **Affiliations (`hed__Affiliation__c`)** link Contacts to Accounts with role and status.',
            '  A student can be affiliated with a Department (as Student), a Sports Organization (as Athlete), etc.',
            '- **Never create custom person/organization objects.** EDA uses standard Account and Contact with managed Record Types and Affiliations.',
            '',
            '### Core EDA Objects',
            '| Object | API Name | Purpose |',
            '|--------|----------|---------|',
            '| Course | `hed__Course__c` | Academic course catalog entry (e.g., CS 101) |',
            '| Course Enrollment | `hed__Course_Enrollment__c` | Student registration in a specific course offering |',
            '| Course Offering | `hed__Course_Offering__c` | Instance of a course in a specific term and facility |',
            '| Term | `hed__Term__c` | Academic period (semester, quarter, trimester) |',
            '| Program Plan | `hed__Program_Plan__c` | Degree requirements and course sequencing |',
            '| Plan Requirement | `hed__Plan_Requirement__c` | Individual requirement within a program plan |',
            '| Facility | `hed__Facility__c` | Physical location (building, room, lab) |',
            '| Affiliation | `hed__Affiliation__c` | Contact-to-Account relationship with role and status |',
            '| Application | `Application__c` | Admissions application record |',
            '| Program Enrollment | `ProgramEnrollment` | Student enrollment in a degree program |',
            '| Contact (Student) | `Contact` | Student record with EDA managed fields |',
            '| Account (Department) | `Account` | Institutional unit with EDA Record Types |',
            '',
            '### EDA Record Types on Account',
            '- `Academic_Program` — A degree or certificate program',
            '- `University_Department` — An academic department',
            '- `Educational_Institution` — The university or college entity',
            '- `Sports_Organization` — Athletic teams and organizations',
            '- `Business_Organization` — External businesses (for internships, partnerships)',
            '- Match institutional units to these Record Types before proposing custom objects.',
            '',
            '## Student Lifecycle',
            '- **Recruitment:** Prospect identification, inquiry management, event tracking, communications',
            '- **Admissions:** Application submission, document collection, review workflows, decision processing, yield management',
            '- **Enrollment:** Course registration, program enrollment, schedule building, waitlist management',
            '- **Advising:** Academic advising, success plans, early alerts, degree audit, milestone tracking',
            '- **Alumni:** Alumni engagement, giving management, career services, mentorship programs',
            '',
            '## Recruitment & Admissions',
            '- Use `Application__c` for admissions application records. Track stages via Status picklist.',
            '- **Application review workflow:** Use Record-Triggered Flows for status transitions (Submitted → Under Review → Decision Made → Accepted/Denied).',
            '- **Decision processing:** Automate offer letter generation, deposit tracking, enrollment confirmation.',
            '- **Yield management:** Track admitted-to-enrolled conversion via reports and dashboards.',
            '- Model recruitment events via Campaign and CampaignMember — do NOT create custom event objects.',
            '- Connect inquiry forms to Lead or Contact creation with appropriate Affiliation records.',
            '',
            '## Academic Operations',
            '- **Course scheduling:** `hed__Course_Offering__c` links a `hed__Course__c` to a `hed__Term__c` and `hed__Facility__c`.',
            '  One course can have multiple offerings per term (sections).',
            '- **Program plans (`hed__Program_Plan__c`):** Define degree requirements as a hierarchy of `hed__Plan_Requirement__c` records.',
            '  Each requirement specifies credits, course category, or specific course.',
            '- **Degree audit:** Compare completed `hed__Course_Enrollment__c` records against `hed__Plan_Requirement__c` to determine progress.',
            '- **Term configuration:** Define terms with start/end dates, registration open/close dates.',
            '  Terms are children of the institutional Account.',
            '- **Grading:** Use `hed__Course_Enrollment__c` grade fields. Do NOT create custom grading objects.',
            '',
            '## Advising & Student Success',
            '- **Success plans:** Track student academic progress, interventions, and milestones.',
            '- **Early alerts:** Configure alert triggers based on GPA thresholds, attendance, or engagement metrics.',
            '- **Appointment scheduling:** Use native Salesforce scheduling or integrated calendar solutions.',
            '- **Milestones:** Track key student lifecycle events (orientation, midterm check-in, graduation application).',
            '- **Advisor assignment:** Use Account Team or custom assignment logic to link advisors to students.',
            '- **Case management for student issues:** Use Service Cloud Cases with Education-specific Record Types for student concerns.',
            '',
            '## Managed Package Safety Rules (hed__ namespace)',
            '- **Do NOT add Apex triggers directly on EDA managed objects** (`hed__Course__c`, `hed__Affiliation__c`, etc.).',
            '  Use Record-Triggered Flows or custom extension objects instead.',
            '- **Do NOT delete or rename EDA managed fields.** Extend only — add custom fields with a project prefix.',
            '- **Do NOT override EDA managed page layouts.** Clone them and assign the clone to your Record Type.',
            '- Before each package upgrade, run `sf package version list --package <EDA_PACKAGE_ID>` and review release notes for breaking changes.',
            '- Test in a sandbox with a full package upgrade before promoting to production.',
            '- **Namespace awareness:** All EDA-managed fields and objects use the `hed__` prefix. Custom extensions should use a project-specific prefix.',
            '',
            '## Integration Patterns',
            '### SIS (Student Information System) Integration',
            '- Use Platform Events or Change Data Capture for near-real-time sync with SIS.',
            '- Map SIS student IDs to Contact External ID fields for upsert operations.',
            '- Sync course catalog, enrollment, and grades bidirectionally.',
            '- Handle term-based batch syncs (start of term: enrollment push; end of term: grade pull).',
            '',
            '### LMS (Learning Management System) Sync',
            '- Canvas, Blackboard, Moodle — integrate via REST APIs with Named Credentials.',
            '- Sync course rosters from Salesforce to LMS at enrollment.',
            '- Pull grade and engagement data from LMS back to `hed__Course_Enrollment__c`.',
            '- Use Apex Queueable or Batch for bulk sync operations; @future for single-record callbacks.',
            '',
            '## Security: FERPA Compliance',
            '- **FERPA (Family Educational Rights and Privacy Act)** restricts access to student education records.',
            '- Configure sharing rules to limit student record access to authorized staff only.',
            '- Use Restriction Rules for fine-grained visibility controls by department or program.',
            '- Implement consent-based data sharing for directory information.',
            '- Audit trail: enable Field History Tracking on sensitive student fields.',
            '- Do NOT expose student GPA, grades, or disciplinary records in public-facing Experience Cloud sites without explicit consent.',
            '- Permission Sets for education staff: separate access for Admissions, Advising, Registrar, Financial Aid.',
            '',
            '## Testing Education Cloud',
            '- **Use TestDataFactory** to create student Contacts, institutional Accounts, Course Offerings, and Enrollments.',
            '- Create test hierarchies: University Account → Department Account → Program Account.',
            '- Test Affiliation creation: link student Contact to Department with role = "Student".',
            '- Test Course Enrollment workflows: create Term, Course, Course Offering, then enroll student.',
            '- Assign EDA Permission Sets to test users in `@TestSetup`.',
            '- Mock SIS/LMS callouts using `Test.setMock(HttpCalloutMock.class, ...)` pattern.',
            ...testCoverageStandards(),
            '',
            ...flsAndCrudEnforcement(),
            '',
            ...documentationStandards(),
            '',
            ...deployment(),
            '',
            ...semanticCommits(),
            '',
            ...generatedPromptsProtocol(),
            '',
            '## Education Cloud References',
            '- Education Cloud Developer Guide: https://developer.salesforce.com/docs/atlas.en-us.education_cloud.meta/education_cloud/',
            '- EDA Object Reference: https://developer.salesforce.com/docs/atlas.en-us.api_eda.meta/api_eda/',
            '- Education Cloud Architecture: https://help.salesforce.com/s/articleView?id=sf.edu_cloud_architecture.htm',
            '',
            ...salesforceReferences(),
            ...getSharedSectionLines('education'),
            '',
            ...interactionPreferences('Education Cloud configuration'),
        ].join('\n');
    },
};
//# sourceMappingURL=education.js.map