{
  "flowName": "EnterpriseDemo_CBPA_Flow2A_SelfAppraisal",
  "version": "1.0-MVP+",
  "description": "Sanitized Power Automate blueprint for unlicensed regional employee self-appraisal intake, mandatory cross-border consent verification, tenure-based question exemption, and null-safe partial edits.",
  "trigger": {
    "type": "MicrosoftForms.WhenNewResponseSubmitted",
    "formId": "<DEMO_FORM_2_SELF_APPRAISAL_ID>",
    "authentication": "AnyoneCanRespond (Mitigated via Record Matching + Mandatory Consent Gate)"
  },
  "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_SelfAppraisal",
      "type": "Scope",
      "controls": [
        {
          "gate": "Status_RecordMatching_And_CrossBorderConsent_Gate",
          "condition": "Status == '1_SelfAppraisalPending' AND SubmissionKey matches AND toLower(InputEmail) == toLower(AppraiseeEmail) AND not(empty(CrossBorderConsentCheckbox))",
          "onFail": "Terminate (Succeeded) — Blocks replay submissions, mismatched records, or unconsented cross-border payloads"
        },
        {
          "action": "Apply_Tenure_Exemption_And_NullSafe_Partial_Edit",
          "rules": [
            "If CommencementDate > '2026-01-01', set SelfQ1_7 = 'Not Applicable (Joined after Jan 1, 2026)'",
            "For returned partial edits, blank fields preserve prior SharePoint values via nested empty() guard before int()/float() casting",
            "Persist CrossBorderConsent = true (timestamped automatically via SharePoint Version History)"
          ]
        },
        {
          "action": "Advance_State_And_Notify_HQ_Manager",
          "updates": {
            "Status": "2_ManagerScoringPending",
            "CrossBorderConsent": true
          },
          "notification": "Send pre-filled Demo-Form 3 link and self-appraisal summary to manager@companydemo.com"
        }
      ]
    }
  ]
}
