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

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

        public override Task<bool> CreateAsync(Domain.Entities.JobEntities.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.JobEntities.Job> objs)
        {
            objs.ForEach(job =>
            {
                if (job.AutoControl == null)
                    job.AutoControl = new JobAutoControl
                    {
                        JobId = job.Id
                    };
            });

            return base.AddRangeAsync(objs);
        }
    }
}
