using Microsoft.Extensions.Logging;
using PARR.Core.Repositories.Interfaces.Job;
using PARR.DAL.Context;
using PARR.DAL.Repositories.Base;
using PARR.Domain.Entities.Job;

namespace PARR.DAL.Repositories.Job
{
    internal class JobRepository : BaseRepository<Domain.Entities.Job.Job>, IJobRepository
    {
        public JobRepository(DataContext dataContext, ILogger<JobRepository> logger) : base(logger, dataContext) { }

        public override Task<bool> CreateAsync(Domain.Entities.Job.Job obj)
        {
            if (obj.AutoControl == null)
                obj.AutoControl = new JobAutoControl
                {
                    JobId = obj.Id
                };

            return base.CreateAsync(obj);
        }


        public override Task<bool> AddRangeAsync(List<Domain.Entities.Job.Job> objs)
        {
            objs.ForEach(job =>
            {
                if (job.AutoControl == null)
                    job.AutoControl = new JobAutoControl
                    {
                        JobId = job.Id
                    };
            });

            return base.AddRangeAsync(objs);
        }
    }
}
