package com.heyu.api.data.service.impl;

import com.heyu.api.data.kuaidi100.ActionDTO;
import com.heyu.api.data.entity.vv.VvTradeOrderLineEntity;
import com.heyu.api.data.enums.ActionEnums;
import com.heyu.api.data.utils.CollectionUtils;
import com.heyu.api.data.service.impl.order.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public abstract class AbstractOrderAction {


    public abstract ActionEnums getAction(VvTradeOrderLineEntity vvTradeOrderLineEntity, boolean isApp);

    public static final List<AbstractOrderAction> actions = Arrays.asList(
            new ApplyRefund(),
            new ApplyReturnRefund(),
            new BuyerCloseReverseOrderAction(),
            new BuyerUploadReverseTrackNumberAction(),
            new CancelAction(),
            new CloseAction(),
            new DeleteAction(),
            new DeliveredAction(),
            new ShippedAction(),
            new ToShippingAction(),
            new TrackLogisticsAction(),
            new UnShippingAction(),
            new AppToPayAction(),
            new BuyerSubmitCommentAction()
    );

    public static List<ActionDTO> getOrderActionDTO(VvTradeOrderLineEntity vvTradeOrderLineEntity, boolean isApp) {
        List<ActionDTO> actionDTOS = new ArrayList<>();
        for (AbstractOrderAction action : actions) {
            ActionEnums orderActionEnums = action.getAction(vvTradeOrderLineEntity, isApp);
            if (orderActionEnums != null) {
                ActionDTO orderActionDTO = new ActionDTO();
                orderActionDTO.setDesc(orderActionEnums.getDesc());
                orderActionDTO.setButtonName(orderActionEnums.getButtonName());
                orderActionDTO.setInterfaceUri(orderActionEnums.getInterfaceUri());
                actionDTOS.add(orderActionDTO);
            }
        }
        return actionDTOS;
    }

    public static boolean checkFailed(VvTradeOrderLineEntity vvTradeOrderLineEntity, boolean isApp, ActionEnums orderActionEnums) {
        List<ActionDTO> orderActionDTOS = getOrderActionDTO(vvTradeOrderLineEntity, isApp);
        if (CollectionUtils.isNotEmpty(orderActionDTOS)) {
            for (ActionDTO orderActionDTO : orderActionDTOS) {
                if (orderActionDTO.getButtonName().equals(orderActionEnums.getButtonName())) {
                    return false;
                }
            }
        }
        return true;
    }


}
