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

namespace Models.Repositories
{
    public class PhSProfessionalSpecialtyRepository(PhronCareOperationsHubContext context) : IPhSProfessionalSpecialtyRepository
    {
        #region Declaraciones y Constructor
        private readonly PhronCareOperationsHubContext _context = context;
        #endregion
        #region Metodos de clase
        public async Task<IEnumerable<EProfessionalSpecialty>> GetAllAsync()
        {
            var specialties = await _context.PhSProfessionalSpecialties.ToListAsync();
            return specialties.Select(EntityMapper.MapEntity<PhSProfessionalSpecialty, EProfessionalSpecialty>);
        }

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