services:
  _defaults:
    autowire: true
    autoconfigure: true
    public: false

  MUTHSEV\CartUnzerpayment\:
    resource: '../Classes/*'

  # Clear current cart to avoid increment orderNumbers when aborting payment
#  MUTHSEV\CartUnzerpayment\EventListener\Order\Payment\ClearCart:
#    tags:
#      - name: event.listener
#        identifier: 'cart-unzerpayment--order--payment--clear-cart'
#        event: Extcode\Cart\Event\Order\PaymentEvent
#        before: 'cart-unzerpayment--order--payment--provider-redirect'

  # todo: should we use the regular Cart FinishEvent
  MUTHSEV\CartUnzerpayment\EventListener\Order\Payment\ClearCart:
    tags:
      - name: event.listener
        identifier: 'cart-unzerpayment--order--payment--clear-cart'
        after: 'cart--unzerpayment--finish--email'
        # event: MUTHSEV\CartUnzerpayment\Event\Order\FinishEvent
        event: Extcode\Cart\Event\Order\FinishEvent

  MUTHSEV\CartUnzerpayment\EventListener\Order\Payment\ProviderRedirect:
    tags:
      - name: event.listener
        identifier: 'cart-unzerpayment--order--payment--provider-redirect'
        event: Extcode\Cart\Event\Order\PaymentEvent

  # Use original event to send email
  # todo: should this be renamed to Notify Event?
#  MUTHSEV\CartUnzerpayment\EventListener\Order\Finish\Email:
#    class: 'Extcode\Cart\EventListener\Order\Finish\Email'
#    tags:
#      - name: event.listener
#        identifier: 'cart--unzerpayment--finish--email'
#        event: MUTHSEV\CartUnzerpayment\Event\Order\FinishEvent
#        # event: Extcode\Cart\Event\Order\FinishEvent

  # With this
#  MUTHSEV\CartUnzerpayment\EventListener\Order\Finish:
#    class: 'Extcode\Cart\EventListener\Order\Finish'
#    tags:
#      - name: event.listener
#        identifier: 'cart-unzerpayment--order--finish--email'
#        event: MUTHSEV\CartUnzerpayment\Event\Order\FinishEvent
