using Microsoft.Extensions.Logging;
using PARR.Core.Repositories.Interfaces.TemplateRepositories;
using PARR.DAL.Context;
using PARR.Domain.Entities.TemplateEntities;

namespace PARR.DAL.Repositories.TemplateRepositories
{
    internal class TemplateRenamePendingRepository : ITemplateRenamePendingRepository
    {
        private readonly DataContext _dataContext;
        private readonly ILogger<TemplateRenamePendingRepository> _logger;

        public TemplateRenamePendingRepository(
                DataContext dataContext,
                ILogger<TemplateRenamePendingRepository> logger
            )
        {
            _dataContext = dataContext;
            _logger = logger;
        }


        public IQueryable<TemplateRenamePending> Get()
        {
            return _dataContext.TemplateRenamePendings;
        }

        public async Task<bool> CreateAsync(TemplateRenamePending obj)
        {
            try
            {
                await _dataContext.TemplateRenamePendings.AddAsync(obj);
                return true;
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Ошибка при добавлении объекта типа TemplateRenamePending в БД");
                return false;
            }
        }
    }
}
