using Microsoft.Extensions.Logging;
using Quartz;

namespace Netina.Core.QuartzServices;

public class JobScheduler(IScheduler scheduler, ILogger<JobScheduler> 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()} ===========");

    }
}