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("每小时执行", "0 0 0/1 * * *"), ONE_AM("每天一点整", "0 0 13 * * *");

    private final String text;
    private final String cron;

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

    public static EmailCron getEmailCronByText(String 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 String getText()
    {
        return text;
    }

    public String getCron()
    {
        return cron;
    }
}
