using Microsoft.Extensions.Logging;
using Quartz;

namespace Netina.Core.QuartzServices;

public class JobScheduler
{
    private readonly IScheduler _scheduler;
    private readonly ILogger<JobScheduler> _logger;

    public JobScheduler(IScheduler scheduler, ILogger<JobScheduler> logger)
    {
        _scheduler = scheduler;
        _logger = logger;
    }

    public void Start()
    {
        _scheduler.Start();

        IJobDetail job = JobBuilder.Create<SiteMapScheduledJob>()
            .WithIdentity("SiteMapJob", "admin")
            .Build();
        ITrigger trigger = TriggerBuilder.Create()
            .WithIdentity("SiteMapJobTrigger", "admin")
            .WithSchedule(CronScheduleBuilder.AtHourAndMinuteOnGivenDaysOfWeek(1, 10,
                DayOfWeek.Saturday,
                DayOfWeek.Sunday,
                DayOfWeek.Monday,
                DayOfWeek.Tuesday,
                DayOfWeek.Wednesday,
                DayOfWeek.Thursday,
                DayOfWeek.Friday))
            .StartNow()
            .Build();
        var offset = _scheduler.ScheduleJob(job, trigger);


        _logger.LogInformation($"======== Table Schedulers Set For {offset.Result.ToString()} IN {DateTime.Now.ToString()} ===========");

    }
}