using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HuanMeng.DotNetCore.QuartzExtend;

/// <summary>
/// 自定义特性，用于标识 Quartz 作业的触发器配置。
/// </summary>
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
public class QuartzTriggerAttribute : Attribute
{
    /// <summary>
    /// 获取触发器的名称。
    /// </summary>
    public string TriggerName { get; }

    /// <summary>
    /// 获取触发器的时间间隔（秒）。
    /// </summary>
    public int? IntervalInSeconds { get; }

    /// <summary>
    /// 获取 Cron 表达式。
    /// </summary>
    public string CronExpression { get; }

    /// <summary>
    /// 使用 Cron 表达式初始化特性。
    /// </summary>
    /// <param name="triggerName">触发器名称。</param>
    /// <param name="cronExpression">Cron 表达式。</param>
    public QuartzTriggerAttribute(string triggerName, string cronExpression = "0/1 * * * * ?")
    {
        TriggerName = triggerName;
        IntervalInSeconds = null;
        CronExpression = cronExpression;
    }

    /// <summary>
    /// 使用时间间隔初始化特性。
    /// </summary>
    /// <param name="triggerName">触发器名称。</param>
    /// <param name="intervalInSeconds">时间间隔（秒）。</param>
    public QuartzTriggerAttribute(string triggerName, int intervalInSeconds)
    {
        TriggerName = triggerName;
        IntervalInSeconds = intervalInSeconds;
        CronExpression = "";
    }
}
