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

import com.heyu.api.data.entity.vv.VvCommentEntity;
import com.heyu.api.data.enums.ActionEnums;
import com.heyu.api.data.kuaidi100.ActionDTO;
import com.heyu.api.data.service.impl.comment.SellerAgreeCommentAction;
import com.heyu.api.data.service.impl.comment.SellerRejectCommentAction;
import com.heyu.api.data.utils.CollectionUtils;

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

public abstract class AbstractCommentAction {

    public abstract ActionEnums getAction(VvCommentEntity vvCommentEntity, boolean isApp, boolean isAdmin);

    public static final List<AbstractCommentAction> actions = Arrays.asList(
            new SellerAgreeCommentAction(),
            new SellerRejectCommentAction()
    );

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



    public static ActionDTO getCommentAction(VvCommentEntity vvCommentEntity, boolean isApp, String buttonName) {
        List<ActionDTO> orderActionDTOS = getOrderActionDTO(vvCommentEntity, isApp);
        if (CollectionUtils.isNotEmpty(orderActionDTOS)) {
            for (ActionDTO orderActionDTO : orderActionDTOS) {
                if (orderActionDTO.getButtonName().equals(buttonName)) {
                    return orderActionDTO;
                }
            }
        }
        return null;
    }


    public static boolean checkFailed(VvCommentEntity vvReverseOrderEntity, boolean isApp, String buttonName) {
        ActionDTO orderActionDTO = getCommentAction(vvReverseOrderEntity, isApp, buttonName);
        if (orderActionDTO != null) {
            return false;
        }
        return true;
    }

}
