package com.braintree.actions.order;

import de.hybris.platform.core.enums.OrderStatus;
import de.hybris.platform.orderprocessing.events.OrderFraudCustomerNotificationEvent;
import de.hybris.platform.orderprocessing.model.OrderProcessModel;
import de.hybris.platform.processengine.action.AbstractProceduralAction;
import de.hybris.platform.servicelayer.event.EventService;
import de.hybris.platform.servicelayer.util.ServicesUtil;


public class BrainTreeNotifyCustomerAboutFraudAction extends AbstractProceduralAction<OrderProcessModel> {

    private static final String PROCESS_CAN_NOT_BE_NULL_MESSAGE = "Process can not be null";
    private static final String ORDER_CAN_NOT_BE_NULL_MESSAGE = "Order can not be null";
    private EventService eventService;

    @Override
    public void executeAction(final OrderProcessModel process) {
        ServicesUtil.validateParameterNotNull(process, PROCESS_CAN_NOT_BE_NULL_MESSAGE);
        ServicesUtil.validateParameterNotNull(process.getOrder(), ORDER_CAN_NOT_BE_NULL_MESSAGE);
        process.getOrder().setStatus(OrderStatus.SUSPENDED);
        getModelService().save(process.getOrder());
        eventService.publishEvent(new OrderFraudCustomerNotificationEvent(process));
    }

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

}
