{
  "key": "vertical-ai-agriculture-farm-equipment-hire-marketplace-v1",
  "name": "Agriculture AI \u2014 Farm equipment hire marketplace",
  "chartOfAccounts": {
    "defaultCurrency": {
      "code": "USD"
    },
    "defaultCurrencyMode": "single",
    "defaultConsistencyConfig": {
      "totalBalanceUpdates": "strong"
    },
    "accounts": [
      {
        "key": "assets",
        "type": "asset",
        "children": [
          {
            "key": "confirmed-cash"
          }
        ]
      },
      {
        "key": "liabilities",
        "type": "liability",
        "children": [
          {
            "key": "sources",
            "template": true,
            "children": [
              {
                "key": "available"
              },
              {
                "key": "cases",
                "template": true,
                "children": [
                  {
                    "key": "held"
                  }
                ]
              },
              {
                "key": "refunds",
                "template": true,
                "children": [
                  {
                    "key": "pending"
                  }
                ]
              }
            ]
          },
          {
            "key": "payees",
            "template": true,
            "children": [
              {
                "key": "cases",
                "template": true,
                "children": [
                  {
                    "key": "approved"
                  },
                  {
                    "key": "payouts",
                    "template": true,
                    "children": [
                      {
                        "key": "pending"
                      }
                    ]
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "key": "income",
        "type": "income",
        "children": [
          {
            "key": "cases",
            "template": true
          }
        ]
      }
    ]
  },
  "ledgerEntries": {
    "types": [
      {
        "type": "farm_equipment_hire_marketplace_fund",
        "description": "Record a confirmed incoming payment; does not execute a payment",
        "lines": [
          {
            "key": "line_1",
            "account": {
              "path": "assets/confirmed-cash"
            },
            "amount": "{{amount}}"
          },
          {
            "key": "line_2",
            "account": {
              "path": "liabilities/sources:{{source_id}}/available"
            },
            "amount": "{{amount}}"
          }
        ]
      },
      {
        "type": "farm_equipment_hire_marketplace_reserve",
        "description": "Reserve customer prepayment for an authorized case",
        "lines": [
          {
            "key": "line_1",
            "account": {
              "path": "liabilities/sources:{{source_id}}/available"
            },
            "amount": "-{{amount}}"
          },
          {
            "key": "line_2",
            "account": {
              "path": "liabilities/sources:{{source_id}}/cases:{{case_id}}/held"
            },
            "amount": "{{amount}}"
          }
        ],
        "conditions": [
          {
            "account": {
              "path": "liabilities/sources:{{source_id}}/available"
            },
            "postcondition": {
              "totalBalance": {
                "gte": "0"
              }
            }
          }
        ]
      },
      {
        "type": "farm_equipment_hire_marketplace_release",
        "description": "Release an unused case hold to available customer funds",
        "lines": [
          {
            "key": "line_1",
            "account": {
              "path": "liabilities/sources:{{source_id}}/cases:{{case_id}}/held"
            },
            "amount": "-{{amount}}"
          },
          {
            "key": "line_2",
            "account": {
              "path": "liabilities/sources:{{source_id}}/available"
            },
            "amount": "{{amount}}"
          }
        ],
        "conditions": [
          {
            "account": {
              "path": "liabilities/sources:{{source_id}}/cases:{{case_id}}/held"
            },
            "postcondition": {
              "totalBalance": {
                "gte": "0"
              }
            }
          }
        ]
      },
      {
        "type": "farm_equipment_hire_marketplace_complete",
        "description": "Split an accepted service amount between payee obligation and platform fee",
        "lines": [
          {
            "key": "line_1",
            "account": {
              "path": "liabilities/sources:{{source_id}}/cases:{{case_id}}/held"
            },
            "amount": "-{{amount}}"
          },
          {
            "key": "line_2",
            "account": {
              "path": "liabilities/payees:{{payee_id}}/cases:{{case_id}}/approved"
            },
            "amount": "{{amount}} - {{fee}}"
          },
          {
            "key": "line_3",
            "account": {
              "path": "income/cases:{{case_id}}"
            },
            "amount": "{{fee}}"
          }
        ],
        "conditions": [
          {
            "account": {
              "path": "liabilities/sources:{{source_id}}/cases:{{case_id}}/held"
            },
            "postcondition": {
              "totalBalance": {
                "gte": "0"
              }
            }
          }
        ]
      },
      {
        "type": "farm_equipment_hire_marketplace_credit_service",
        "description": "Undo an approved unpaid service allocation, with explicit fee credit",
        "lines": [
          {
            "key": "line_1",
            "account": {
              "path": "liabilities/payees:{{payee_id}}/cases:{{case_id}}/approved"
            },
            "amount": "-{{payee_credit}}"
          },
          {
            "key": "line_2",
            "account": {
              "path": "income/cases:{{case_id}}"
            },
            "amount": "-{{fee_credit}}"
          },
          {
            "key": "line_3",
            "account": {
              "path": "liabilities/sources:{{source_id}}/available"
            },
            "amount": "{{payee_credit}} + {{fee_credit}}"
          }
        ],
        "conditions": [
          {
            "account": {
              "path": "liabilities/payees:{{payee_id}}/cases:{{case_id}}/approved"
            },
            "postcondition": {
              "totalBalance": {
                "gte": "0"
              }
            }
          },
          {
            "account": {
              "path": "income/cases:{{case_id}}"
            },
            "postcondition": {
              "totalBalance": {
                "gte": "0"
              }
            }
          }
        ]
      },
      {
        "type": "farm_equipment_hire_marketplace_reserve_refund",
        "description": "Reserve a customer refund before calling the payment provider",
        "lines": [
          {
            "key": "line_1",
            "account": {
              "path": "liabilities/sources:{{source_id}}/available"
            },
            "amount": "-{{amount}}"
          },
          {
            "key": "line_2",
            "account": {
              "path": "liabilities/sources:{{source_id}}/refunds:{{refund_id}}/pending"
            },
            "amount": "{{amount}}"
          }
        ],
        "conditions": [
          {
            "account": {
              "path": "liabilities/sources:{{source_id}}/available"
            },
            "postcondition": {
              "totalBalance": {
                "gte": "0"
              }
            }
          }
        ]
      },
      {
        "type": "farm_equipment_hire_marketplace_refund_settled",
        "description": "Record a refund only after the payment provider confirms it settled",
        "lines": [
          {
            "key": "line_1",
            "account": {
              "path": "liabilities/sources:{{source_id}}/refunds:{{refund_id}}/pending"
            },
            "amount": "-{{amount}}"
          },
          {
            "key": "line_2",
            "account": {
              "path": "assets/confirmed-cash"
            },
            "amount": "-{{amount}}"
          }
        ],
        "conditions": [
          {
            "account": {
              "path": "liabilities/sources:{{source_id}}/refunds:{{refund_id}}/pending"
            },
            "postcondition": {
              "totalBalance": {
                "gte": "0"
              }
            }
          },
          {
            "account": {
              "path": "assets/confirmed-cash"
            },
            "postcondition": {
              "totalBalance": {
                "gte": "0"
              }
            }
          }
        ]
      },
      {
        "type": "farm_equipment_hire_marketplace_refund_failed",
        "description": "Release the refund reservation only after definitive failure",
        "lines": [
          {
            "key": "line_1",
            "account": {
              "path": "liabilities/sources:{{source_id}}/refunds:{{refund_id}}/pending"
            },
            "amount": "-{{amount}}"
          },
          {
            "key": "line_2",
            "account": {
              "path": "liabilities/sources:{{source_id}}/available"
            },
            "amount": "{{amount}}"
          }
        ],
        "conditions": [
          {
            "account": {
              "path": "liabilities/sources:{{source_id}}/refunds:{{refund_id}}/pending"
            },
            "postcondition": {
              "totalBalance": {
                "gte": "0"
              }
            }
          }
        ]
      },
      {
        "type": "farm_equipment_hire_marketplace_reserve_payout",
        "description": "Reserve an approved payable before calling the payout provider",
        "lines": [
          {
            "key": "line_1",
            "account": {
              "path": "liabilities/payees:{{payee_id}}/cases:{{case_id}}/approved"
            },
            "amount": "-{{amount}}"
          },
          {
            "key": "line_2",
            "account": {
              "path": "liabilities/payees:{{payee_id}}/cases:{{case_id}}/payouts:{{payout_id}}/pending"
            },
            "amount": "{{amount}}"
          }
        ],
        "conditions": [
          {
            "account": {
              "path": "liabilities/payees:{{payee_id}}/cases:{{case_id}}/approved"
            },
            "postcondition": {
              "totalBalance": {
                "gte": "0"
              }
            }
          }
        ]
      },
      {
        "type": "farm_equipment_hire_marketplace_payout_settled",
        "description": "Record confirmed external payout settlement",
        "lines": [
          {
            "key": "line_1",
            "account": {
              "path": "liabilities/payees:{{payee_id}}/cases:{{case_id}}/payouts:{{payout_id}}/pending"
            },
            "amount": "-{{amount}}"
          },
          {
            "key": "line_2",
            "account": {
              "path": "assets/confirmed-cash"
            },
            "amount": "-{{amount}}"
          }
        ],
        "conditions": [
          {
            "account": {
              "path": "liabilities/payees:{{payee_id}}/cases:{{case_id}}/payouts:{{payout_id}}/pending"
            },
            "postcondition": {
              "totalBalance": {
                "gte": "0"
              }
            }
          },
          {
            "account": {
              "path": "assets/confirmed-cash"
            },
            "postcondition": {
              "totalBalance": {
                "gte": "0"
              }
            }
          }
        ]
      },
      {
        "type": "farm_equipment_hire_marketplace_payout_failed",
        "description": "Release reservation only after definitive external payout failure",
        "lines": [
          {
            "key": "line_1",
            "account": {
              "path": "liabilities/payees:{{payee_id}}/cases:{{case_id}}/payouts:{{payout_id}}/pending"
            },
            "amount": "-{{amount}}"
          },
          {
            "key": "line_2",
            "account": {
              "path": "liabilities/payees:{{payee_id}}/cases:{{case_id}}/approved"
            },
            "amount": "{{amount}}"
          }
        ],
        "conditions": [
          {
            "account": {
              "path": "liabilities/payees:{{payee_id}}/cases:{{case_id}}/payouts:{{payout_id}}/pending"
            },
            "postcondition": {
              "totalBalance": {
                "gte": "0"
              }
            }
          }
        ]
      }
    ]
  },
  "scenes": [
    {
      "name": "Farm equipment hire marketplace \u2014 successful path and confirmed partial failures",
      "events": [
        {
          "eventType": "entry",
          "entry": {
            "type": "farm_equipment_hire_marketplace_fund",
            "typeVersion": 1,
            "parameters": {
              "source_id": "1",
              "amount": "1000"
            }
          }
        },
        {
          "eventType": "entry",
          "entry": {
            "type": "farm_equipment_hire_marketplace_reserve",
            "typeVersion": 1,
            "parameters": {
              "source_id": "1",
              "case_id": "1",
              "amount": "700"
            }
          }
        },
        {
          "eventType": "entry",
          "entry": {
            "type": "farm_equipment_hire_marketplace_complete",
            "typeVersion": 1,
            "parameters": {
              "source_id": "1",
              "case_id": "1",
              "payee_id": "1",
              "fee": "100",
              "amount": "500"
            }
          }
        },
        {
          "eventType": "entry",
          "entry": {
            "type": "farm_equipment_hire_marketplace_credit_service",
            "typeVersion": 1,
            "parameters": {
              "source_id": "1",
              "case_id": "1",
              "payee_id": "1",
              "payee_credit": "80",
              "fee_credit": "20"
            }
          }
        },
        {
          "eventType": "entry",
          "entry": {
            "type": "farm_equipment_hire_marketplace_release",
            "typeVersion": 1,
            "parameters": {
              "source_id": "1",
              "case_id": "1",
              "amount": "200"
            }
          }
        },
        {
          "eventType": "entry",
          "entry": {
            "type": "farm_equipment_hire_marketplace_reserve_refund",
            "typeVersion": 1,
            "parameters": {
              "source_id": "1",
              "refund_id": "1",
              "amount": "200"
            }
          }
        },
        {
          "eventType": "entry",
          "entry": {
            "type": "farm_equipment_hire_marketplace_refund_failed",
            "typeVersion": 1,
            "parameters": {
              "source_id": "1",
              "refund_id": "1",
              "amount": "50"
            }
          }
        },
        {
          "eventType": "entry",
          "entry": {
            "type": "farm_equipment_hire_marketplace_refund_settled",
            "typeVersion": 1,
            "parameters": {
              "source_id": "1",
              "refund_id": "1",
              "amount": "150"
            }
          }
        },
        {
          "eventType": "entry",
          "entry": {
            "type": "farm_equipment_hire_marketplace_reserve_payout",
            "typeVersion": 1,
            "parameters": {
              "case_id": "1",
              "payee_id": "1",
              "payout_id": "1",
              "amount": "320"
            }
          }
        },
        {
          "eventType": "entry",
          "entry": {
            "type": "farm_equipment_hire_marketplace_payout_failed",
            "typeVersion": 1,
            "parameters": {
              "case_id": "1",
              "payee_id": "1",
              "payout_id": "1",
              "amount": "20"
            }
          }
        },
        {
          "eventType": "entry",
          "entry": {
            "type": "farm_equipment_hire_marketplace_payout_settled",
            "typeVersion": 1,
            "parameters": {
              "case_id": "1",
              "payee_id": "1",
              "payout_id": "1",
              "amount": "300"
            }
          }
        }
      ]
    }
  ]
}
