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

import com.heyu.api.data.entity.vv.VvPromoterTradeOrderAwardEntity;
import com.heyu.api.data.enums.ActionEnums;
import com.heyu.api.data.kuaidi100.ActionDTO;
import com.heyu.api.data.service.impl.draw.AgreeDrawAction;
import com.heyu.api.data.service.impl.draw.ApplyDrawAction;
import com.heyu.api.data.service.impl.draw.RejectDrawAction;
import com.heyu.api.data.utils.CollectionUtils;

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

public abstract class AbstractDrawAction {


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


    public static final List<AbstractDrawAction> actions = Arrays.asList(
            new AgreeDrawAction(),
            new ApplyDrawAction(),
            new RejectDrawAction()
    );

    public static List<ActionDTO> getDrawActionDTO(VvPromoterTradeOrderAwardEntity vvPromoterTradeOrderAwardEntity, boolean isApp) {
        List<ActionDTO> actionDTOS = new ArrayList<>();
        for (AbstractDrawAction action : actions) {
            ActionEnums orderActionEnums = action.getAction(vvPromoterTradeOrderAwardEntity, 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(VvPromoterTradeOrderAwardEntity vvTradeOrderLineEntity, boolean isApp, ActionEnums orderActionEnums) {
        List<ActionDTO> orderActionDTOS = getDrawActionDTO(vvTradeOrderLineEntity, isApp);
        if (CollectionUtils.isNotEmpty(orderActionDTOS)) {
            for (ActionDTO orderActionDTO : orderActionDTOS) {
                if (orderActionDTO.getButtonName().equals(orderActionEnums.getButtonName())) {
                    return false;
                }
            }
        }



        return true;
    }


}
