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

namespace Models.Repositories
{
    public class PhSDocumentTypeRepository (PhronCareOperationsHubContext context): IPhSDocumentTypeRepository
    {
        #region Declaraciones y Constructor
        private readonly PhronCareOperationsHubContext _context = context;
        #endregion
        #region Metodos de clase
        public async Task<IEnumerable<EDocumentType>> GetAllAsync()
        {
            var documentTypes = await _context.PhSDocumentTypes.ToListAsync();
            return documentTypes.Select(EntityMapper.MapEntity<PhSDocumentType, EDocumentType>);
        }
        public async Task<EDocumentType?> GetByNameAsync(string name)
        {
            var documentType = await _context.PhSDocumentTypes.FirstOrDefaultAsync(a => a.Name.Contains(name));
            return documentType != null ? EntityMapper.MapEntity<PhSDocumentType, EDocumentType>(documentType) : null;
        }
        #endregion
    }
}
