{
  "flowName": "EnterpriseDemo_CBPA_Flow2B_ScoringEngine",
  "version": "1.0-MVP+",
  "description": "Sanitized Power Automate blueprint for HQ licensed manager scoring, dual-evidence innovation enforcement, and extreme score gating.",
  "trigger": {
    "type": "MicrosoftForms.WhenNewResponseSubmitted",
    "formId": "<DEMO_FORM_3_MANAGER_SCORING_ID>",
    "authentication": "OnlyPeopleInMyOrganisation (Entra ID)"
  },
  "steps": [
    {
      "step": 1,
      "name": "Get_response_details",
      "action": "MicrosoftForms.GetResponseDetails"
    },
    {
      "step": 2,
      "name": "Lookup_Appraisal_Record",
      "action": "SharePoint.GetItems",
      "siteUrl": "https://demo-tenant.sharepoint.com/sites/EnterpriseDemo-CBPA",
      "listName": "Demo_Appraisal_2026",
      "filterQuery": "Title eq '<AppraisalID>'"
    },
    {
      "step": 3,
      "name": "Scope_Supervisor",
      "type": "Scope",
      "controls": [
        {
          "gate": "Status_And_Identity_Authorization_Gate",
          "condition": "Status == '2_ManagerScoringPending' AND SubmissionKey matches AND toLower(responder) == toLower(AppraiserEmail)",
          "onFail": "Terminate (Succeeded) — Silent drop to prevent spoofing or duplicate webhooks"
        },
        {
          "branch": "Return_To_Employee",
          "condition": "Decision == 'Return to Employee'",
          "actions": [
            "Update Status -> '1_SelfAppraisalPending'",
            "Increment RevisionCount + 1",
            "Write ReturnReason & send pre-filled Demo-Form 2 link to employee@companydemo.com"
          ]
        },
        {
          "branch": "Deterministic_Scoring_Engine",
          "condition": "Decision == 'Submit Score'",
          "actions": [
            "Evaluate varEvidenceMissing across EmpRemark08 AND SupRemark08 (length >= 4 and not in invalid placeholder list)",
            "Preserve SupQ08 (original) and compute SupQ08_Eff = if(varEvidenceMissing, 0, SupQ08)",
            "Calculate weighted subtotals with weights [2,2,2,3,3,3,3,1,1] and map Grades A-F",
            "Extreme Score Gate: if (TotalScore <= 50 OR TotalScore > 80) AND empty(ExtremeScoreReason) -> block progression & notify manager@companydemo.com",
            "Update SharePoint record -> Status = '3_EmployeeConfirmPending'",
            "Send HTML preview email (strictly hiding HR Section D) + pre-filled Demo-Form 4 link to employee@companydemo.com"
          ]
        }
      ]
    }
  ]
}
