<?xml version="1.0" encoding="UTF-8"?>
<flow xmlns="http://www.springframework.org/schema/webflow"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.springframework.org/schema/webflow http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">

	<secured attributes="ROLE_USER" />

	<persistence-context/>
	
	<input name="hotelId" />
	
	<on-start>
		<evaluate expression="bookingService.createBooking(hotelId, currentUser.name)" result="flowScope.booking" />
	</on-start>
	
	<view-state id="enterBookingDetails" model="booking">
		<transition on="proceed" to="reviewBooking" />
		<transition on="cancel" to="cancel" bind="false" />
	</view-state>
	
	<view-state id="reviewBooking" model="booking">
		<transition on="confirm" to="bookingConfirmed">
			<evaluate expression="persistenceContext.persist(booking)" />
		</transition>
		<transition on="revise" to="enterBookingDetails" />
		<transition on="cancel" to="cancel" />
	</view-state>
	
	<end-state id="bookingConfirmed" commit="true" />

	<end-state id="cancel"/>
		
</flow>