package com.simuwang.base.common.enums;

import java.util.stream.Stream;

/**
 * FileName: EMAIL_CRON
 * Author:   chenjianhua
 * Date:     2024/9/9 13:50
 * Description: ${DESCRIPTION}
 */
public enum EmailCron {
    EVERY_HOUR(1, "0 0/1 * * * ?"), ONE_AM(2, "0 0 1 * * ?");

    private final Integer text;
    private final String cron;

    EmailCron(Integer text, String cron)
    {
        this.text = text;
        this.cron = cron;
    }

    public static EmailCron getEmailCronByText(Integer text) {
        if (null == text){
            return null;
        }
        for(EmailCron s : EmailCron.values()){
            if(text.equals(s.getText())){
                return s;
            }
        }
        return null;
    }

    public static EmailCron getEmailCronByCron(String cron) {
        return Stream.of(EmailCron.values()).filter(e -> e.cron.equals(cron)).findFirst().orElse(null);
    }

    public Integer getText()
    {
        return text;
    }

    public String getCron()
    {
        return cron;
    }
}
