<workflow>

	<rule match="$.services[*].units[?(@.state.hostname is None)]" desc="Units with no hostname">
		<set path="state.hostname">
			<generate-hostname>
				<parameter name="pattern"><select path="::unitNamingPattern"/></parameter>
				<parameter name="service_id"><select path="::id"/></parameter>
			</generate-hostname>
		</set>
	</rule>

	<rule match="$[?(not @.state.deleted)]" desc="Search through all the environments..">
		<rule match="$.services[*].units[*]" desc="If any units exists" limit="1">
			<mute/>
            <empty>
				<delete-cf-stack>
					<success>
						<set path="/state.deleted"><true/></set>
					</success>
				</delete-cf-stack>
			</empty>
		</rule>
	</rule>

</workflow>