using Microsoft.Extensions.Logging;
using PARR.BLL.Services.Interfaces;
using System.Text.Json;

namespace PARR.BLL.Services.Implementations
{
    internal class TransformService: ITransformService
    {
        private readonly ILogger<TransformService> logger;

        public TransformService(ILogger<TransformService> logger)
        {
            this.logger = logger;
        }

        public T? GetModelFromJson<T>(string str)
        {
            try
            {
                return JsonSerializer.Deserialize<T>(str);
            }
            catch (Exception ex)
            {
                logger.LogError(ex, $"Ошибка при конвертации строки в модель. {str}");

                return default;
            }
        }
    }
}
