using System;
using System.Globalization;

namespace SepehrHotelApiSampleClient.BuiltinTypeExtensions
{
    public static class StringExtension
    {
        public static T DeserializeFromJson<T>(this string input)
        {
            return Newtonsoft.Json.JsonConvert.DeserializeObject<T>(input);
        }

        public static DateTime ParseAsGregorianDate(this string date)
        {
            try
            {
                return DateTime.ParseExact(date, "yyyy-M-d", CultureInfo.InvariantCulture);
            }
            catch (Exception exception)
            {
                throw new Exception($"'{date}' is not valid date format. Valid format is yyyy-MM-dd Technical Error: {exception.Message}");
            }
        }
    }
}
