{
  "flowName": "EnterpriseDemo_CBPA_Flow3_HTMLBatchApproval",
  "version": "1.0-MVP+",
  "description": "Sanitized Power Automate blueprint for concurrency-safe batch gating, inline HTML summary table generation, executive approval, and post-cycle read-only archive locking.",
  "trigger": {
    "type": "SharePoint.WhenItemIsCreatedOrModified",
    "siteUrl": "https://demo-tenant.sharepoint.com/sites/EnterpriseDemo-CBPA",
    "listName": "Demo_Appraisal_2026",
    "settings": {
      "concurrencyControl": true,
      "degreeOfParallelism": 1,
      "triggerConditions": "@and(equals(triggerOutputs()?['body/Status/Value'], '5_HRReviewPending'), equals(triggerOutputs()?['body/HRApproved'], true))"
    }
  },
  "steps": [
    {
      "step": 1,
      "name": "Batch_Completion_Gate",
      "actions": [
        "Get_All_Active: IsExempt ne 1 and Status ne '6_ManagementApprovalPending' and Status ne '7_Archived'",
        "Get_Ready_Batch: IsExempt ne 1 and Status eq '5_HRReviewPending' and HRApproved eq 1",
        "Condition: length(Get_All_Active) == length(Get_Ready_Batch) AND length(Get_Ready_Batch) > 0 (otherwise Terminate)"
      ]
    },
    {
      "step": 2,
      "name": "Lock_Batch_And_Build_HTML_Table",
      "actions": [
        "Update all Get_Ready_Batch items to Status = '6_ManagementApprovalPending'",
        "Create HTML table with AppraisalID, Employee, Department, Manager, TotalScore, InnovationCheck, HRDSuggestions, and ListItemLink",
        "Apply inline CSS table borders and header styling via Compose"
      ]
    },
    {
      "step": 3,
      "name": "Executive_Approval_And_ReadOnly_Lock",
      "actions": [
        "Start and wait for an approval assigned to director@companydemo.com with inline HTML summary table & SharePoint Management View link",
        "On Approve -> Update all batch items to Status = '7_Archived'",
        "Execute SharePoint 'Stop sharing an item or a file' + 'Grant access (Can view)' for hr-approver@, hr-support@, and director@"
      ]
    }
  ]
}
