using Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Models.Interfaces;
using Models.Helpers;
using Models.Models;

namespace Models.Repositories
{
    public class PhOhTaxConditionRepository(PhronCareOperationsHubContext context): IPhSTaxConditionRepository
    {
        #region Declaraciones y Constructor
        private readonly PhronCareOperationsHubContext _context = context;
        #endregion
        #region Metodos de clase
        public async Task<IEnumerable<ETaxCondition>> GetAllAsync()
        {
            var taxConditions = await _context.PhOhTaxConditions.ToListAsync();
            return taxConditions.Select(EntityMapper.MapEntity<PhOhTaxCondition, ETaxCondition>);
        }
        public async Task<ETaxCondition?> GetByNameAsync(string name)
        {
            var taxCondition = await _context.PhOhTaxConditions.FirstOrDefaultAsync(a => a.Description.Contains(name));
            return taxCondition != null ? EntityMapper.MapEntity<PhOhTaxCondition, ETaxCondition>(taxCondition) : null;
        }
        #endregion
    }
}
