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

namespace Models.Repositories
{
    public class PhSAccountTypeRepository(PhronCareOperationsHubContext context) : IPhSAccountTypeRepository
    {
        #region Declaraciones y Constructor
        private readonly PhronCareOperationsHubContext _context = context;
        #endregion
        #region Metodos de clase
        public async Task<IEnumerable<EAccountType>> GetAllAsync()
        {
            var accountTypes = await _context.PhSAccountTypes.ToListAsync();
            return accountTypes.Select(EntityMapper.MapEntity<PhSAccountType, EAccountType>);
        }

        public async Task<EAccountType?> GetByNameAsync(string name)
        {
            var accountType = await _context.PhSAccountTypes.FirstOrDefaultAsync(a => a.Name.Contains(name));
            return accountType != null ? EntityMapper.MapEntity<PhSAccountType, EAccountType>(accountType) : null;
        }
        #endregion
    }
}
