package com.braintree.actions.consignment;


import de.hybris.platform.basecommerce.enums.ConsignmentStatus;
import de.hybris.platform.ordersplitting.model.ConsignmentModel;
import de.hybris.platform.ordersplitting.model.ConsignmentProcessModel;
import de.hybris.platform.processengine.action.AbstractAction;
import org.apache.log4j.Logger;

import java.util.HashSet;
import java.util.Set;


public class BrainTreeConfirmConsignmentPickupAction extends AbstractAction<ConsignmentProcessModel> {

    private static final Logger LOG = Logger.getLogger(BrainTreeConfirmConsignmentPickupAction.class);
    private static final String PROCESS_HAS_NO_CONSIGNMENT_LOG_MSG = "Process has no consignment";

    public enum Transition {
        OK, CANCEL, ERROR;

        public static Set<String> getStringValues() {
            final Set<String> res = new HashSet<String>();

            for (final Transition transition : Transition.values()) {
                res.add(transition.toString());
            }
            return res;
        }
    }

    @Override
    public String execute(final ConsignmentProcessModel process) {
        final ConsignmentModel consignment = process.getConsignment();
        if (consignment != null) {
            consignment.setStatus(ConsignmentStatus.PICKUP_COMPLETE);
            getModelService().save(consignment);
            return Transition.OK.toString();
        }
        LOG.error(PROCESS_HAS_NO_CONSIGNMENT_LOG_MSG);
        return Transition.ERROR.toString();
    }

    @Override
    public Set<String> getTransitions() {
        return Transition.getStringValues();
    }

}
