using Lada.Framework.Data.Domains.Cms;
using Lada.Framework.Data.Repositories;
using ladaexpress.vn.Infrastructures.Stores;
using Microsoft.EntityFrameworkCore;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace ladaexpress.vn.Infrastructures.Startup
{
    public class ScriptConfigStartupTask : IStartupTask
    {
        private readonly IRepository<ScriptConfig> _scriptConfigRepository;

        public ScriptConfigStartupTask(IRepository<ScriptConfig> scriptConfigRepository)
        {
            _scriptConfigRepository = scriptConfigRepository;
        }

        public async Task ExecuteAsync(CancellationToken cancellationToken = default)
        {
            ScriptConfigStore.AllScripts = await _scriptConfigRepository
                .Query()
                .Where(x => x.IsActive)
                .ToListAsync(cancellationToken);
        }
    }
}
