package com.hzs.common.core.enums;

import com.hzs.common.core.constant.EnumsPrefixConstants;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 伞下直推新增业绩订单类型枚举
 */
@AllArgsConstructor
@Getter
public enum EOrderBusiness {

    /**
     * 全部 报单订单 + 消费订单 + 复消订单+ 虚拟订单
     */
    WHOLE(1, "全部", 0, EnumsPrefixConstants.ORDER_BUSINESS + 1),

    /**
     * 首购  报单订单 + 消费订单
     */
    FIRST_PURCHASE(2, "首购", 0, EnumsPrefixConstants.ORDER_BUSINESS + 2),

    /**
     * 复消订单
     */
    REPURCHASE(3, "复购", 0, EnumsPrefixConstants.ORDER_BUSINESS + 3),

    /**
     * 报单订单
     */
    REGISTER_ORDER(5, "报单订单", 0, EnumsPrefixConstants.ORDER_BUSINESS + 5),

    /**
     * 消费订单
     */
    UPGRADE_ORDER(6, "消费订单", 0, EnumsPrefixConstants.ORDER_BUSINESS + 6),

    /**
     * 虚拟订单
     */
    FICTITIOUS_ORDER(7, "虚拟订单", 0, EnumsPrefixConstants.ORDER_BUSINESS + 7),

    ;

    /**
     * 实际值
     */
    private final int value;
    /**
     * 显示标签
     */
    private final String label;
    /**
     * 是否启用（0=是,1=否） -- 来源EYesNo
     */
    private final int enable;
    /**
     * 国际化翻译key值
     */
    private final String key;

    /**
     * 根据值，返回枚举
     *
     * @param value
     * @return
     */
    public static EOrderBusiness getEnumByValue(int value) {
        for (EOrderBusiness eOrderType : EOrderBusiness.values()) {
            if (eOrderType.getValue() == value) {
                return eOrderType;
            }
        }
        return null;
    }


    /**
     * 会员前端列表
     */
    private static List<EOrderBusiness> apiList;

    /**
     * 获取会员前端列表
     *
     * @return
     */
    public static List<EOrderBusiness> getApiList() {
        if (null == apiList) {
            apiList = new ArrayList<>();
            Collections.addAll(apiList, EOrderBusiness.values());
        }
        return apiList;
    }

    public static List<Integer> getOrderTypeList(Integer value) {
        List<Integer> orderTypeList = new ArrayList<>();
        if (null == value || EOrderBusiness.WHOLE.getValue() == value) {
            orderTypeList.add(EOrderType.REGISTER_ORDER.getValue());
            orderTypeList.add(EOrderType.UPGRADE_ORDER.getValue());
            orderTypeList.add(EOrderType.RESALE_ORDER.getValue());
            orderTypeList.add(EOrderType.FICTITIOUS_ORDER.getValue());
        } else if (EOrderBusiness.FIRST_PURCHASE.getValue() == value) {
            //首购
            orderTypeList.add(EOrderType.REGISTER_ORDER.getValue());
            orderTypeList.add(EOrderType.UPGRADE_ORDER.getValue());
            orderTypeList.add(EOrderType.FICTITIOUS_ORDER.getValue());
        } else if (EOrderBusiness.REPURCHASE.getValue() == value) {
            //复购
            orderTypeList.add(EOrderType.RESALE_ORDER.getValue());
        } else if (EOrderBusiness.REGISTER_ORDER.getValue() == value) {
            orderTypeList.add(EOrderType.REGISTER_ORDER.getValue());
        } else if (EOrderBusiness.UPGRADE_ORDER.getValue() == value) {
            orderTypeList.add(EOrderType.UPGRADE_ORDER.getValue());
        } else if (EOrderBusiness.FICTITIOUS_ORDER.getValue() == value) {
            orderTypeList.add(EOrderType.FICTITIOUS_ORDER.getValue());
        }
        return orderTypeList;
    }

}
