/*
 * 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 generateNetzeroWorkflows(version) {
    return {
        'carbon-accounting-setup.md': workflow(version, 'Carbon Accounting Setup', `
## 1. Gather Requirements

Ask:
- **Emission scopes:** Which scopes need tracking? Scope 1 (direct emissions), Scope 2 (purchased electricity), Scope 3 (supply chain)?
- **Emission sources:** What are the primary sources? Stationary combustion, mobile sources, fugitive emissions, purchased goods?
- **Factor libraries:** Which emission factor libraries apply? EPA (US), DEFRA (UK), IEA (global), or custom factors?
- **Data collection frequency:** Monthly, quarterly, or annual reporting cycles?
- **Organizational boundary:** Operational control, financial control, or equity share approach?
- **Base year:** What is the emissions base year for reduction target calculations?

Check \`force-app/main/default/objects/\` for existing Net Zero Cloud objects (\`StnryAssetEnvrSrc\`, \`BldgEnergyIntensity\`, \`VhclAssetEnvrSrc\`) before adding custom fields.

## 2. Configure Emission Sources

### Stationary Asset Environmental Sources
- Use \`StnryAssetEnvrSrc\` for fixed-location emission sources (boilers, furnaces, generators).
- Key fields: fuel type, consumption quantity, emission factor, calculated CO2e.
- Link each source to a building/facility record for location-based reporting.

### Vehicle Asset Environmental Sources
- Use \`VhclAssetEnvrSrc\` for fleet and mobile emission sources.
- Key fields: vehicle type, fuel type, distance traveled, fuel consumed.
- Categorize as Scope 1 (company-owned) or Scope 3 (employee commuting, business travel).

### Building Energy Intensity
- Use \`BldgEnergyIntensity\` for tracking energy use per building.
- Key fields: energy source (grid electricity, natural gas, renewable), consumption kWh, intensity per sqft.
- Scope 2 emissions derive from grid electricity consumption multiplied by location-based or market-based factors.

## 3. Set Up Emission Factor Libraries

1. Navigate to Setup → Net Zero Cloud → Emission Factors.
2. Import reference data from the applicable factor library:
   - **EPA eGRID** — US electricity grid factors by subregion.
   - **DEFRA** — UK government conversion factors for GHG reporting.
   - **IEA** — International Energy Agency country-level factors.
3. Create custom emission factors for organization-specific sources not covered by standard libraries.
4. Set effective date ranges on factors — factors change annually with updated publications.
5. Link factors to emission source records via the Emission Factor lookup field.

## 4. Configure Data Collection

### Utility Bill Import
- Set up data connectors or manual import templates for monthly utility bills.
- Map bill fields: account number, meter ID, consumption (kWh/therms), billing period, cost.
- Validate imported data against previous periods (flag anomalies > 20% variance).

### IoT Sensor Integration (Optional)
- Configure Platform Events for real-time energy meter data ingestion.
- Use a Queueable Apex class to batch-process sensor readings into \`EnergyUseRecord\` entries.
- Set up error handling for dropped or duplicate sensor readings.

### Supply Chain Data (Scope 3)
- Define data templates for supplier-provided emission data.
- Use spend-based estimation when activity data is unavailable.
- Track data quality scores per supplier (primary data vs estimates).

## 5. Deploy Carbon Accounting Metadata

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

Verify in the target org:
- Emission source records calculate CO2e correctly using assigned factors
- Building energy records aggregate to facility-level totals
- Scope 1/2/3 categorization is accurate on all source records
`),
        'esg-reporting-setup.md': workflow(version, 'ESG Reporting Setup', `
## 1. Gather Requirements

Ask:
- **Reporting frameworks:** Which frameworks does the organization report against? GRI, SASB, TCFD, CDP, CSRD, ISSB?
- **Disclosure scope:** Which ESG topics are material? (Run a materiality assessment if not completed.)
- **Reduction targets:** Are there approved science-based targets (SBTi)? What is the target year and reduction percentage?
- **Dashboard audience:** Who consumes ESG dashboards? Sustainability team, C-suite, board, external auditors?
- **Audit requirements:** Is third-party assurance required? What level — limited or reasonable assurance?
- **Reporting period:** Fiscal year or calendar year? Does it align with financial reporting?

## 2. Select and Map Reporting Frameworks

### Framework Alignment
Map each framework's disclosure requirements to Net Zero Cloud data fields:

| Framework | Focus Area | Key Disclosures |
|-----------|-----------|-----------------|
| GRI | Broad ESG | GRI 305 (Emissions), GRI 302 (Energy), GRI 303 (Water), GRI 306 (Waste) |
| SASB | Industry-specific | Sector-dependent metrics (e.g., GHG intensity per revenue) |
| TCFD | Climate risk | Governance, Strategy, Risk Management, Metrics & Targets |
| CDP | Climate disclosure | Scope 1/2/3 emissions, reduction targets, climate risks |
| CSRD | EU mandatory | Double materiality, ESRS standards, digital tagging (XBRL) |

### Disclosure Mapping
1. For each required disclosure, identify the Net Zero Cloud object and field that provides the data.
2. Document gaps where manual data entry or external integration is needed.
3. Create Custom Metadata records to map framework questions to Salesforce fields for automated population.

## 3. Configure Sustainability Goals and Targets

### Science-Based Targets (SBTi)
- Use \`SustainabilityGoal\` to define reduction targets.
- Key fields: base year emissions, target year, reduction percentage, scope, pathway (1.5°C or well-below 2°C).
- Configure interim milestones (e.g., 42% reduction by 2030 for 1.5°C alignment).

### Forecasting and Scenario Modeling
- Set up reduction pathways: BAU (business as usual) vs target scenario.
- Model interventions: renewable energy procurement, fleet electrification, supplier engagement.
- Use \`CarbonFootprint\` records to track actual vs projected emissions per period.
- Configure dashboard comparisons: actual trajectory vs SBTi-required trajectory.

## 4. Configure ESG Dashboards

### Executive Dashboard
- Total emissions by scope (Scope 1, 2, 3) — current year vs prior year.
- Progress toward SBTi targets — actual vs required reduction curve.
- Energy mix: renewable vs non-renewable percentage.
- Top 10 emission sources by CO2e contribution.

### Operational Dashboard
- Emissions by facility/building — drill-down to individual sources.
- Monthly energy consumption trends with anomaly highlighting.
- Data completeness score — percentage of expected data received per period.
- Supplier emission data quality tracker.

### Compliance Dashboard
- Framework disclosure status: complete, in progress, gap.
- Audit trail: last modified date, modified by, change reason for all reported values.
- Assurance readiness checklist per disclosure item.

## 5. Configure Audit Trail and Data Lineage

### Change Tracking
- Enable Field History Tracking on all emission source objects (CO2e, consumption, factor fields).
- Configure Setup Audit Trail monitoring for emission factor changes.
- Use \`EmissionsSource\` records to maintain a clear lineage from raw data to reported totals.

### Regulatory Compliance
- Document calculation methodology per emission source (activity-based, spend-based, average-data).
- Maintain version history of emission factors applied per reporting period.
- Store supporting evidence (utility bills, invoices, supplier declarations) as Files linked to source records.

## 6. Deploy ESG Reporting Configuration

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

Verify in the target org:
- Sustainability goals display correct base year, target year, and reduction pathway
- Dashboards render with accurate scope breakdowns
- Audit trail captures all field changes on emission source records
- Framework disclosure mapping correctly pulls data from source objects
`),
    };
}
//# sourceMappingURL=netzero.js.map