{
	"name": "Case behandeling",
	"app": "dossiq",
	"trigger": "object.created",
	"nodes": [
		{
			"id": "start",
			"type": "openregister.trigger-object",
			"config": {
				"event": "object.created",
				"register": "dossiq",
				"schema": "case"
			}
		},
		{
			"id": "status-ontvangen",
			"type": "dossiq.setStatus",
			"config": {
				"status": "Ontvangen"
			}
		},
		{
			"id": "check-complete",
			"type": "openregister.switch",
			"config": {},
			"_note": "The conditions live HERE, on exits[], because that is the engine's contract: FlowTokenRouter reads a node's exits and follows edges by fromExit. They used to sit on the edges themselves, where the engine never looks. Every enabled transition then appeared unconditional, the first one won, and a COMPLETE case was routed to 'Wacht op aanvulling'. Exits are tried in declaration order; the one without a condition is the required else.",
			"exits": [
				{
					"id": "compleet",
					"condition": {
						"!!": [
							{
								"var": "json.description"
							}
						]
					}
				},
				{
					"id": "onvolledig",
					"condition": {
						"<": [
							{
								"var": "json.aanvullingRound"
							},
							3
						]
					}
				},
				{
					"id": "gestrand"
				}
			]
		},
		{
			"id": "count-round",
			"type": "openregister.set-fields",
			"config": {
				"compute": {
					"aanvullingRound": {
						"+": [
							{
								"var": "json.aanvullingRound"
							},
							1
						]
					}
				}
			}
		},
		{
			"id": "status-wacht",
			"type": "dossiq.setStatus",
			"config": {
				"status": "Wacht op aanvulling"
			}
		},
		{
			"id": "ask-indiener",
			"type": "dossiq.askPerson",
			"config": {
				"question": "Vul uw aanvraag aan",
				"details": "Uw aanvraag is nog niet compleet. Vul de ontbrekende gegevens aan zodat wij verder kunnen.",
				"assignee": "{{ case.assignee }}",
				"dueInDays": "14",
				"signalKey": "aanvulling"
			}
		},
		{
			"id": "status-gestrand",
			"type": "dossiq.setStatus",
			"config": {
				"status": "Gestrand"
			}
		},
		{
			"id": "end-gestrand",
			"type": "openregister.end",
			"config": {}
		},
		{
			"id": "status-behandeling",
			"type": "dossiq.setStatus",
			"config": {
				"status": "In behandeling"
			}
		},
		{
			"id": "decide-register-b",
			"type": "dossiq.requestDecision",
			"config": {
				"question": "Toets de aanvraag aan register B",
				"decisionType": "advice",
				"signalKey": "toetsRegisterB"
			}
		},
		{
			"id": "decide-tweede-toets",
			"type": "dossiq.requestDecision",
			"config": {
				"question": "Tweede inhoudelijke toets",
				"decisionType": "advice",
				"signalKey": "tweedeToets"
			}
		},
		{
			"id": "task-behandelaar",
			"type": "dossiq.askPerson",
			"config": {
				"question": "Rond de inhoudelijke voorbereiding af",
				"details": "Controleer het dossier en maak het gereed voor de planningscommissie.",
				"assignee": "behandelaars",
				"dueInDays": "7",
				"signalKey": "voorbereiding"
			}
		},
		{
			"id": "status-commissie",
			"type": "dossiq.setStatus",
			"config": {
				"status": "Bij commissie"
			}
		},
		{
			"id": "decide-commissie",
			"type": "dossiq.requestDecision",
			"config": {
				"question": "Definitief besluit van de planningscommissie",
				"decisionType": "report-adoption",
				"signalKey": "commissieBesluit"
			}
		},
		{
			"id": "route-besluit",
			"type": "openregister.switch",
			"config": {}
		},
		{
			"id": "besluit-document",
			"type": "dossiq.action.mergeTemplate",
			"_note": "The keys are the ones DossiqMergeTemplateNode REQUIRES (templateSlug + targetField); the first shipped config said template/outputName, which validateConfig refuses at execute(), so every run stranded here and no case could ever close. The `template` key carries the inline template text (HandlesTemplates::renderTemplate reads it first and treats it as the template itself, not a lookup key). targetField must be a property the case schema declares, or the store silently strips the rendered document on save.",
			"config": {
				"templateSlug": "besluit",
				"template": "Besluit op de aanvraag {{case.title}} ({{case.identifier}}). De planningscommissie heeft de aanvraag beoordeeld. Uitkomst: {{case.commissieBesluit.decision}}. Dit besluit is vastgelegd bij afronding van de behandeling.",
				"targetField": "besluitDocument"
			}
		},
		{
			"id": "status-afgehandeld",
			"type": "dossiq.setStatus",
			"config": {
				"status": "Afgehandeld"
			}
		},
		{
			"id": "end",
			"type": "openregister.end",
			"config": {}
		}
	],
	"edges": [
		{
			"id": "e-start",
			"from": "start",
			"to": "status-ontvangen"
		},
		{
			"id": "e-ontvangen",
			"from": "status-ontvangen",
			"to": "check-complete"
		},
		{
			"id": "e-compleet",
			"from": "check-complete",
			"fromExit": "compleet",
			"to": "status-behandeling",
			"label": "compleet"
		},
		{
			"id": "e-onvolledig",
			"from": "check-complete",
			"fromExit": "onvolledig",
			"to": "status-wacht",
			"label": "onvolledig"
		},
		{
			"id": "e-gestrand",
			"from": "check-complete",
			"fromExit": "gestrand",
			"to": "status-gestrand",
			"label": "gestrand"
		},
		{
			"id": "e-wacht",
			"from": "status-wacht",
			"to": "count-round"
		},
		{
			"id": "e-count",
			"from": "count-round",
			"to": "ask-indiener"
		},
		{
			"id": "e-heraanbieding",
			"from": "ask-indiener",
			"to": "check-complete"
		},
		{
			"id": "e-gestrand-end",
			"from": "status-gestrand",
			"to": "end-gestrand"
		},
		{
			"id": "e-behandeling",
			"from": "status-behandeling",
			"to": "decide-register-b"
		},
		{
			"id": "e-toets1",
			"from": "decide-register-b",
			"to": "decide-tweede-toets"
		},
		{
			"id": "e-toets2",
			"from": "decide-tweede-toets",
			"to": "task-behandelaar"
		},
		{
			"id": "e-taak",
			"from": "task-behandelaar",
			"to": "status-commissie"
		},
		{
			"id": "e-commissie",
			"from": "status-commissie",
			"to": "decide-commissie"
		},
		{
			"id": "e-besluit",
			"from": "decide-commissie",
			"to": "route-besluit"
		},
		{
			"id": "e-toegekend",
			"from": "route-besluit",
			"to": "besluit-document",
			"label": "besluit genomen"
		},
		{
			"id": "e-document",
			"from": "besluit-document",
			"to": "status-afgehandeld"
		},
		{
			"id": "e-end",
			"from": "status-afgehandeld",
			"to": "end"
		}
	]
}
