<?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-1.0.xsd">

  <start-state idref="captcha"/>

  <subflow-state id="captcha" flow="captcha-sub-flow">
    <transition on="finish" to="init"/>
  </subflow-state>

  <decision-state id="init">
    <entry-actions>
      <action bean="account.passwordReissueAction" method="init"/>
    </entry-actions>
    <if test="${flowScope.sendMail}" then="reissueAutoForm" else="reissueAutoManual"/>
  </decision-state>

  <!-- Auto -->
  <view-state id="reissueAutoForm" view="account.PasswordReissueForm">
    <render-actions>
      <action bean="account.passwordReissueAction" method="setupForm"/>
    </render-actions>
    <transition on="submit" to="reissueAuto">
      <action bean="account.passwordReissueAction" method="bindAndValidate"/>
    </transition>
  </view-state>

  <action-state id="reissueAuto">
    <action bean="account.passwordReissueAction" method="generateTemporaryAuthKey"/>
    <transition on="success" to="reissueAutoFinish"/>
    <!-- エラーの場合、終了してしまう -->
    <transition on-exception="org.unitedfront2.web.controller.account.AccountNotFoundException" to="reissueAutoFinish"/>
  </action-state>

  <end-state id="reissueAutoFinish" view="account.PasswordReissueConfirm"/>

  <!-- Manual -->
  <action-state id="reissueAutoManual">
    <action bean="account.passwordReissueAction" method="prepareManual"/>
    <transition on="success" to="reissueManual"/>
  </action-state>

  <subflow-state id="reissueManual" flow="mail/inquiry-flow">
    <attribute-mapper>
      <input-mapper>
        <input-attribute name="subject" required="true"/>
      </input-mapper>
    </attribute-mapper>
    <transition on="finish" to="reissueManualFinish"/>
  </subflow-state>

  <end-state id="reissueManualFinish" view="mail.InquirySuccess"/>

</flow>
