take_rack_to_pps:
  params:
    - BId
    - RId
    - PPSId
  bb_keys:
    - pps_location
  definition:
    sequence:
      name: "Take Rack to PPS"
      decorators: 
        - module: values_set_decorator
          args:
            keys: [BId, RId, PPSId]
        - module: succeed_if_true_decorator
          args:
            name: "Rack already at PPS"
            module: butler_functions
            function: rack_already_at_pps
            args: [RId, PPSId]
      children:
        task:
          name: "Get PPS Location"
          module: get_pps_location_task
          args:
            pps_id: PPSId
            pps_location: pps_location
          # don't really need to recalculate pps position since it won't change...
          decorators:
            - module: succeed_if_set_decorator
              args:
                keys: [pps_location]
        take_rack_to_location:
          name: "Take Rack To PPS Location"
          ref: ./take_rack_to_location.yml
          args:
            BId: BId
            RId: RId
            RackDestination: pps_location

single_rackloop:
  params:
    - BId
  bb_keys:
    - rack_id
    - pps_id
    - storable
    - is_storing
  definition:
    sequence:
      name: "Single Rackloop"
      children:
        task:
          name: "Choose Rack and PPS"
          # choose rack and pps for task
          module: choose_rack_and_pps_task
          args:
            bid: BId
            rack_id: rack_id
            pps_id: pps_id
          # succeed if already chosen
          decorators:
            - module: succeed_if_set_decorator
              args:
                keys: [rack_id, pps_id]
        # take rack to pps
        take_rack_to_pps:
          name: "Take Rack to PPS"
          args:
            BId: BId
            RId: rack_id
            PPSId: pps_id
          decorators:
            # succeed if is_storing is set
            - module: succeed_if_set_decorator
              args:
                keys: [is_storing]
        # wait at pps
        task:
          name: "Wait at PPS"
          module: wait_task
          args:
            time: 5
          decorators:
            # succeed if is_storing is set
            - module: succeed_if_set_decorator
              args:
                keys: [is_storing]
        # transition to is_storing state
        task:
          name: "Change state to is_storing phase"
          module: set_var_task
          args:
            var: is_storing
            value: true
        # choose storable
        task:
          name: "Choose Storable"
          module: choose_storable_task
          args:
            rack_id: rack_id
            storable: storable
          decorators:
            # succeed if already chosen
            - module: succeed_if_set_decorator
              args:
                keys: [storable]
        # take rack to storable location
        take_rack_to_location:
          name: "Take Rack to Storable Location"
          ref: ./take_rack_to_location.yml
          args:
            BId: BId
            RId: rack_id
            RackDestination: storable

rackloop_with_count:
  params:
    - BId
    - Count
  definition:
    sequence:
      name: "Looped Rackloop"
      decorators:
        - module: loop_decorator
          args:
            count: Count
      children:
        single_rackloop:
          args:
            BId: BId