using Hangfire;
using TakeoutSaaS.Module.Scheduler.Abstractions;
using TakeoutSaaS.Module.Scheduler.Jobs;

namespace TakeoutSaaS.Module.Scheduler.Services;

/// <summary>
/// 周期性任务注册器。
/// </summary>
public sealed class RecurringJobRegistrar : IRecurringJobRegistrar
{
    /// <inheritdoc />
    public Task RegisterAsync(CancellationToken cancellationToken = default)
    {
        // 1. 业务占位任务（示例）
        RecurringJob.AddOrUpdate<OrderTimeoutJob>("orders.timeout-cancel", job => job.ExecuteAsync(), "*/5 * * * *");
        RecurringJob.AddOrUpdate<CouponExpireJob>("coupons.expire", job => job.ExecuteAsync(), "0 */1 * * *");
        RecurringJob.AddOrUpdate<LogCleanupJob>("logs.cleanup", job => job.ExecuteAsync(), "0 3 * * *");

        // 2. (空行后) 门店管理自动化任务
        RecurringJob.AddOrUpdate<BusinessStatusAutoSwitchJob>(
            "stores.business-status-auto-switch",
            job => job.ExecuteAsync(),
            "*/1 * * * *");
        RecurringJob.AddOrUpdate<QualificationExpiryCheckJob>(
            "stores.qualification-expiry-check",
            job => job.ExecuteAsync(),
            "0 2 * * *");

        return Task.CompletedTask;
    }
}
