package com.smppw.common.pojo.enums;

import cn.hutool.core.collection.CollUtil;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author Yu Liu
 */
public enum Frequency {
    /**
     * 日频
     */
    Daily(1, "d", 252, "日频", "天"),
    /**
     * 周频
     */
    Weekly(2, "w", 52, "周频", "周"),
    /**
     * 月频
     */
    Monthly(3, "m", 12, "月频", "月"),
    /**
     * 季频
     */
    Quarterly(4, "q", 4, "季频", "季"),
    /**
     * 半年频
     */
    SemiAnnually(5, "s", 2, "半年频", "半年"),
    /**
     * 年频
     */
    Annually(6, "y", 1, "年频", "年"),
    /**
     * 实际频率
     */
    Default(0, "def", -1, "实际频率", "实际频率");

    private final int id;
    private final String shortName;
    private final double num;
    private final String desc;

    private final String navFrequencyName;

    Frequency(int id, String shortName, double num, String desc, String navFrequencyName) {
        this.id = id;
        this.shortName = shortName;
        this.num = num;
        this.desc = desc;
        this.navFrequencyName = navFrequencyName;
    }

    public static Frequency getFrequency(String shortName) {
        return Stream.of(Frequency.values()).filter(e -> e.shortName.equals(shortName)).findFirst().orElse(null);
    }

    /**
     * 根据指定频率id获取对应的频率
     * @param id 频率id
     * @return /
     */
    public static Frequency getFrequency(int id) {
        return Stream.of(Frequency.values()).filter(e -> e.getId() == id).findFirst().orElse(null);
    }

    public static Frequency getFrequencyByDesc(String desc) {
        return Stream.of(Frequency.values()).filter(e -> e.desc.equals(desc)).findFirst().orElse(null);
    }

    /**
     * 获取
     * 
     * @param frequency
     *            给定频率
     * @return /
     */
    public static List<Frequency> getThanTargetFreq(Frequency frequency) {
        List<Frequency> res = CollUtil.newArrayList();
        if (frequency == null) {
            return res;
        }
        return Stream.of(Frequency.values())
            .filter(e -> e != Frequency.Default && e.getId() >= frequency.getId() && e.getId() > 1)
            .collect(Collectors.toList());
    }

    public double getNum() {
        return num;
    }

    public int getId() {
        return id;
    }

    public String getShortName() {
        return shortName;
    }

    public String getDesc() {
        return desc;
    }

    public String getNavFrequencyName() {
        return navFrequencyName;
    }
}
