using Microsoft.Extensions.Logging;
using PARR.Core.Common.Interfaces;
using System.Text.Json;

namespace PARR.Core.Common.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;
            }
        }
    }
}
