package com.braintree.email.emailServices;

import com.braintree.email.emailEvents.BraintreeLocalPaymentReversedEmailEvent;
import de.hybris.platform.core.model.order.OrderModel;
import de.hybris.platform.core.model.user.CustomerModel;
import de.hybris.platform.servicelayer.event.EventService;
import de.hybris.platform.servicelayer.event.events.AbstractEvent;
import de.hybris.platform.servicelayer.i18n.CommonI18NService;
import de.hybris.platform.site.BaseSiteService;
import de.hybris.platform.store.services.BaseStoreService;

import java.text.MessageFormat;

public class BraintreeLocalPaymentReversedEmailEventService {

    private EventService eventService;
    private BaseSiteService baseSiteService;
    private BaseStoreService baseStoreService;
    private CommonI18NService commonI18NService;

    /**
     * This method send a BraintreeLocalPaymentReversedEmailEvent
     * @param customerModel customer model
     * @param orderModel order model
     */
    public void sendBraintreeLocalPaymentReversedEmailEvent(final CustomerModel customerModel, final OrderModel orderModel)
    {
        eventService.publishEvent(initializeBraintreeLocalPaymentReversedEmailEvent(
                new BraintreeLocalPaymentReversedEmailEvent(), customerModel, orderModel));
    }

    private AbstractEvent initializeBraintreeLocalPaymentReversedEmailEvent(final BraintreeLocalPaymentReversedEmailEvent event,
                                                        final CustomerModel customerModel, final OrderModel orderModel){
        event.setBaseStore(orderModel.getStore());
        event.setSite(orderModel.getSite());
        event.setCustomer(customerModel);
        event.setLanguage(orderModel.getLanguage());
        event.setCurrency(orderModel.getCurrency());
        event.setContent(MessageFormat
                .format("Your Order {0} was not placed successful - Automated Message - DO NOT REPLY",
                        orderModel.getCode()));
        event.setOrderModel(orderModel);

        return event;
    }

    public void setEventService(EventService eventService) {
        this.eventService = eventService;
    }

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

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

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