package com.braintree.listeners;

import com.braintree.constants.BraintreefulfilmentprocessConstants;
import de.hybris.platform.orderprocessing.events.PickupConfirmationEvent;
import de.hybris.platform.ordersplitting.model.ConsignmentModel;
import de.hybris.platform.ordersplitting.model.ConsignmentProcessModel;
import de.hybris.platform.processengine.BusinessProcessService;
import de.hybris.platform.servicelayer.event.impl.AbstractEventListener;
import org.springframework.beans.factory.annotation.Required;


/**
 * Listener for pickup confirmation events.
 */
public class BrainTreePickupConfirmationEventListener extends AbstractEventListener<PickupConfirmationEvent> {

    private BusinessProcessService businessProcessService;

    @Override
    protected void onEvent(final PickupConfirmationEvent pickupConfirmationEvent) {
        final ConsignmentModel consignmentModel = pickupConfirmationEvent.getProcess().getConsignment();
        for (final ConsignmentProcessModel process : consignmentModel.getConsignmentProcesses()) {
            businessProcessService.triggerEvent(
                    process.getCode() + "_" + BraintreefulfilmentprocessConstants.CONSIGNMENT_PICKUP);
        }
    }

    public void setBusinessProcessService(final BusinessProcessService businessProcessService) {
        this.businessProcessService = businessProcessService;
    }

}
