<?xml version="1.0" encoding="UTF-8"?>
<process xmlns:blue="http://www.e-marson.com/bluelemon">

  <descriptor>
    <name>com/emarson/lemonade/examples/mobank/moaccount/MainScreen</name>
    <version>1.0</version>
    <description>
      Shows the main screen with the following options:
       - Account balance
       - Transfer
       - History
    </description>
    <vendor>E-MARSON</vendor>
  </descriptor>

  <!-- 
    We want to use this screen in two different scenarios, so 
    the label and the action for exit are both parametrizable.
  --->

  <arguments>
    <argument key="actionForExit" type="ByteArray"/>
    <argument key="labelForExit" type="String"/>
  </arguments>

  <path>

    <!-- ASSOCIATIONS --->
    
    <!-- association to AccountBalanceScreen --->
    <action name="action for 'Balance'">
      <type>general/bluelemon/code</type>
      <definition resultTo="actionGoToAccountBalanceScreen">
        <blue:call node="com/emarson/lemonade/examples/mobank/moaccount/AccountBalanceScreen"
                         location="@com/emarson/lemonade/examples/mobank/moaccount"/>

      </definition>
    </action>

    <!-- association to TransferScreen --->
    <action name="action for 'Transfer'">
      <type>general/bluelemon/code</type>
      <definition resultTo="actionGoToTransferScreen">
        <blue:call node="com/emarson/lemonade/examples/mobank/moaccount/TransferScreen"
                         location="@com/emarson/lemonade/examples/mobank/moaccount"/>

      </definition>
    </action>
    
    <!-- association to HistoryScreen --->
    <action name="action for 'History'">
      <type>general/bluelemon/code</type>
      <definition resultTo="actionGoToHistoryScreen">
        <blue:call node="com/emarson/lemonade/examples/mobank/moaccount/HistoryScreen"
                   location="@com/emarson/lemonade/examples/mobank/moaccount"/>

      </definition>
    </action>
    
    
    <!-- INSTRUCTION --->
    
    <!-- 
      Now we are ready to create the Bluelemon instruction, which will
      show an implicit list of the three elements we need.
      
      We could code it as 'general/bluelemon/code' - but we 
      can also use an existing template, just specifying arguments we need.
      
      One of the arguments is the dataset of type < (rowName: String),
      (actionToBeInvoked: Bluelemon code > which defines the content 
      of the list.
    --->
    
    <action name="menu dataset">
      <type>general/bluelemon/field</type>
      <definition resultTo="menuDataset">

        <blue:field type="dataset">
          <blue:descriptor>
            <blue:field type="String"/>
            <blue:field type="byteArr"/>
          </blue:descriptor>
          <blue:row>
            <blue:field value="Account balance"/>
            <blue:field contextKey="actionGoToAccountBalanceScreen"/>
          </blue:row>
          <blue:row>
            <blue:field value="Transfer"/>
            <blue:field contextKey="actionGoToTransferScreen"/>
          </blue:row>
          <blue:row>
            <blue:field value="History"/>
            <blue:field contextKey="actionGoToHistoryScreen"/>
          </blue:row>
        </blue:field>

      </definition>
    </action>
    
    <!-- Having all we need, let's generate the code... --->
    <subprocess name="main screen">
      <source>com/emarson/lemonade/templates/ImplicitListWindow</source>
      <arguments>
        <argument key="title">"mobank: Account"</argument>
        <argument key="elementsDataset">menuDataset</argument>
        <argument key="backAction">actionForExit</argument>
        <argument key="backActionText">labelForExit</argument>
      </arguments>
      <resultTo>mainScreen</resultTo>
    </subprocess>

    <!-- ... and return the result --->
    <finish name="done">
      <return>mainScreen</return>
    </finish>

  </path>

</process>