package com.braintree.listener;

import com.braintree.event.BraintreeUnlinkCustomerNotificationEvent;
import com.braintree.model.BraintreeUnlinkCustomerNotificationProcessModel;
import de.hybris.platform.core.model.user.CustomerModel;
import de.hybris.platform.processengine.BusinessProcessService;
import de.hybris.platform.servicelayer.event.impl.AbstractEventListener;
import de.hybris.platform.servicelayer.i18n.CommonI18NService;
import de.hybris.platform.servicelayer.model.ModelService;
import de.hybris.platform.servicelayer.user.UserService;
import de.hybris.platform.site.BaseSiteService;
import de.hybris.platform.store.services.BaseStoreService;

public class BraintreeUnlinkCustomerNotificationListener extends AbstractEventListener<BraintreeUnlinkCustomerNotificationEvent> {

    private BusinessProcessService businessProcessService;

    private ModelService modelService;

    private BaseStoreService baseStoreService;

    private BaseSiteService baseSiteService;

    private CommonI18NService commonI18NService;

    private UserService userService;

    @Override
    protected void onEvent(BraintreeUnlinkCustomerNotificationEvent event) {
        BraintreeUnlinkCustomerNotificationProcessModel process = businessProcessService
                .createProcess("braintreeUnlinkCustomerNotification-" + System.currentTimeMillis(),
                        "braintreeUnlinkCustomerNotificationProcess");
        process.setStore(baseStoreService.getCurrentBaseStore());
        process.setLanguage(commonI18NService.getCurrentLanguage());
        process.setCurrency(commonI18NService.getCurrentCurrency());
        process.setSite(baseSiteService.getCurrentBaseSite());
        process.setCustomer((CustomerModel) userService.getUserForUID(event.getUid()));
        modelService.save(process);
        businessProcessService.startProcess(process);
    }

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

    public void setModelService(ModelService modelService) {
        this.modelService = modelService;
    }

    public void setBaseStoreService(BaseStoreService baseStoreService) {
        this.baseStoreService = baseStoreService;
    }

    public void setBaseSiteService(BaseSiteService baseSiteService) {
        this.baseSiteService = baseSiteService;
    }

    public void setCommonI18NService(CommonI18NService commonI18NService) {
        this.commonI18NService = commonI18NService;
    }

    public void setUserService(UserService userService) {
        this.userService = userService;
    }

}
