{
  "apiVersion": 64,
  "label": "OpportunityLineItem Net Fees Autocalc",
  "description": "Stamps OpportunityLineItem.Net_fees__c on every Create/Update before save, branched by PricebookEntry.Product2.Family:\n  - TiDB Enterprise Subscription: Net_fees__c = Unit_Net_Price__c * Quantity * Term_Mounths__c (multi-period term; unit price is quoted per month)\n  - all other families (TiDB Cloud, Professional / Consulting / Training & Exam Services): Net_fees__c = Unit_Net_Price__c * Quantity (one-time)\n\nResolves the Family via PricebookEntry → Product2 lookups (the existing pattern from #1690). Decision conditions reference recordLookup outputs (traversal-time, safe). Formulas reference only $Record.* fields so the early-evaluation pass in evaluateFlowFormulas can resolve them without depending on lookup completion. The earlier annualize-passthrough variant relied on $Record.Net_Fees_Total__c, which no UI surface populates — replaced by direct compute from sales-entered Unit_Net_Price__c, Quantity, and Term_Mounths__c.\n\nRuns at triggerOrder 200, after the autofill chain (PricebookEntryId reverse-resolve 20, Product2 50, Currency 60, ListPrice 85) and after OpportunityLineItem_Expansion_AutoStamp (100). The RecordAfterSave Recalculate_Handler (250) re-fires the save chain when sales clicks the Recalculate button, so Net Fees re-stamps on demand.",
  "status": "Active",
  "processType": "AutoLaunchedFlow",
  "runAtomically": true,
  "start": {
    "triggerOrder": 200,
    "locationX": 0,
    "locationY": 0,
    "object": "OpportunityLineItem",
    "triggerType": "RecordBeforeSave",
    "recordTriggerType": "CreateAndUpdate",
    "connector": {
      "targetReference": "Has_Required_Inputs"
    }
  },
  "decisions": [
    {
      "name": "Has_Required_Inputs",
      "label": "Has Required Inputs",
      "locationX": 0,
      "locationY": 0,
      "defaultConnectorLabel": "Default Outcome",
      "rules": [
        {
          "name": "Yes",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "$Record.PricebookEntryId",
              "operator": "IsNull",
              "rightValue": {
                "booleanValue": false
              }
            },
            {
              "leftValueReference": "$Record.Unit_Net_Price__c",
              "operator": "IsNull",
              "rightValue": {
                "booleanValue": false
              }
            },
            {
              "leftValueReference": "$Record.Quantity",
              "operator": "IsNull",
              "rightValue": {
                "booleanValue": false
              }
            }
          ],
          "connector": {
            "targetReference": "Get_PricebookEntry"
          },
          "label": "Yes"
        }
      ]
    },
    {
      "name": "Family_Is_Subscription",
      "label": "Family Is Subscription",
      "locationX": 0,
      "locationY": 0,
      "defaultConnector": {
        "targetReference": "Stamp_Cloud"
      },
      "defaultConnectorLabel": "Default - One-time (UNP * Qty)",
      "rules": [
        {
          "name": "Subscription",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "Get_Product.Family",
              "operator": "EqualTo",
              "rightValue": {
                "stringValue": "TiDB Enterprise Subscription"
              }
            }
          ],
          "connector": {
            "targetReference": "Stamp_Subscription"
          },
          "label": "Subscription/OP - UNP * Qty * Term"
        }
      ]
    }
  ],
  "recordLookups": [
    {
      "name": "Get_PricebookEntry",
      "label": "Get Price Book Entry",
      "locationX": 0,
      "locationY": 0,
      "assignNullValuesIfNoRecordsFound": false,
      "connector": {
        "targetReference": "Get_Product"
      },
      "filterLogic": "and",
      "filters": [
        {
          "field": "Id",
          "operator": "EqualTo",
          "value": {
            "elementReference": "$Record.PricebookEntryId"
          }
        }
      ],
      "getFirstRecordOnly": true,
      "object": "PricebookEntry",
      "storeOutputAutomatically": true
    },
    {
      "name": "Get_Product",
      "label": "Get Product",
      "locationX": 0,
      "locationY": 0,
      "assignNullValuesIfNoRecordsFound": false,
      "connector": {
        "targetReference": "Family_Is_Subscription"
      },
      "filterLogic": "and",
      "filters": [
        {
          "field": "Id",
          "operator": "EqualTo",
          "value": {
            "elementReference": "Get_PricebookEntry.Product2Id"
          }
        }
      ],
      "getFirstRecordOnly": true,
      "object": "Product2",
      "storeOutputAutomatically": true
    }
  ],
  "formulas": [
    {
      "name": "NetFeesCloud",
      "dataType": "Currency",
      "expression": "{!$Record.Unit_Net_Price__c} * {!$Record.Quantity}"
    },
    {
      "name": "NetFeesSubscription",
      "dataType": "Currency",
      "expression": "{!$Record.Unit_Net_Price__c} * {!$Record.Quantity} * {!$Record.Term_Mounths__c}"
    }
  ],
  "assignments": [
    {
      "name": "Stamp_Cloud",
      "label": "Stamp Cloud Net Fees",
      "locationX": 0,
      "locationY": 0,
      "assignmentItems": [
        {
          "assignToReference": "$Record.Net_fees__c",
          "operator": "Assign",
          "value": {
            "elementReference": "NetFeesCloud"
          }
        }
      ]
    },
    {
      "name": "Stamp_Subscription",
      "label": "Stamp Subscription/OP Net Fees",
      "locationX": 0,
      "locationY": 0,
      "assignmentItems": [
        {
          "assignToReference": "$Record.Net_fees__c",
          "operator": "Assign",
          "value": {
            "elementReference": "NetFeesSubscription"
          }
        }
      ]
    }
  ]
}
