using Core.Interfaces;
using Domain.Entities;
using Models.Interfaces;
using System.Reflection;

namespace Core.Services
{
    public class DocumentTypeService : IDocumentTypeDom
    {
        private readonly IPhSDocumentTypeRepository _repository;

        public DocumentTypeService(IPhSDocumentTypeRepository repository)
        {
            _repository = repository ?? throw new ArgumentNullException(nameof(repository));
        }

        public async Task<IEnumerable<EDocumentType>> GetAllAsync()
        {
            try
            {
                return await _repository.GetAllAsync();
            }
            catch (Exception ex)
            {
                var methodName = MethodBase.GetCurrentMethod()?.Name ?? "UnknownMethod";
                throw new Exception($"{methodName} Message: {ex.Message}", ex);
            }
        }

        public async Task<EDocumentType?> GetByNameAsync(string name)
        {
            try
            {
                return await _repository.GetByNameAsync(name);
            }
            catch (Exception ex)
            {
                var methodName = MethodBase.GetCurrentMethod()?.Name ?? "UnknownMethod";
                throw new Exception($"{methodName} Message: {ex.Message}", ex);
            }
        }
    }
}
