
package com.tmerclub.cloud.flow.constant;


import java.util.Objects;

/**
 * 流量筛选的时间类型
 *
 * @author YXF
 * @date 2021-05-21
 */
public enum FlowDateTypeEnum {
    /**
     * 日
     */
    DAY(1, 1),
    /**
     * 周
     */
    WEEK(2, 1),
    /**
     * 月
     */
    MONTH(3, 1),
    /**
     * 今日实时
     */
    REAL_TIME(4, 1),
    /**
     * 近七天
     */
    NEARLY_WEEK(5, 7),
    /**
     * 近30天
     */
    NEARLY_MONTH(6, 30),
    /**
     * 自定义
     */
    CUSTOM(7, 0);

    private final Integer id;

    private final Integer num;

    public Integer value() {
        return id;
    }

    public Integer getNum() {
        return num;
    }

    FlowDateTypeEnum(Integer id, Integer num) {
        this.id = id;
        this.num = num;
    }

    public static FlowDateTypeEnum instance(Integer value) {
        FlowDateTypeEnum[] enums = values();
        for (FlowDateTypeEnum statusEnum : enums) {
            if (statusEnum.value().equals(value)) {
                return statusEnum;
            }
        }
        return DAY;
    }

    public static FlowDateTypeEnum[] allEnum() {
        return values();
    }

    /**
     * 日、周或者月
     * @return
     */
    public static boolean dayOrWeekOrMonth(Integer id) {
        if (Objects.equals(DAY.id, id) || Objects.equals(WEEK.id, id) || Objects.equals(MONTH.id, id)) {
            return true;
        }
        return false;
    }

    /**
     * 周或者月
     * @return
     */
    public static boolean weekOrMonth(Integer id) {
        return Objects.equals(WEEK.id, id) || Objects.equals(MONTH.id, id);
    }

    /**
     * 周或者月
     * @return
     */
    public static boolean nearlyTime(Integer id) {
        return Objects.equals(NEARLY_WEEK.id, id) || Objects.equals(NEARLY_MONTH.id, id);
    }

    /**
     * 是否为今日实时
     * @return
     */
    public static boolean isRealTime(Integer id) {
        return Objects.equals(REAL_TIME.id, id);
    }
}
