// <auto-generated />
//
// To parse this JSON data, add NuGet 'Newtonsoft.Json' then do:
//
//    using CreateLabel_ML;
//
//    var clsEnvia99Minutos = ClsEnvia99Minutos.FromJson(jsonString);


    using System;
    using System.Collections.Generic;
    using System.Globalization;
    using Newtonsoft.Json;
    using Newtonsoft.Json.Converters;

    public partial class ClsEnvia99Minutos
    {
        [JsonProperty("apikey")]
        public string Apikey { get; set; }

        [JsonProperty("deliveryType")]
        public string DeliveryType { get; set; }

        [JsonProperty("packageSize")]
        public string PackageSize { get; set; }

        [JsonProperty("notes")]
        public string Notes { get; set; }

        [JsonProperty("cahsOnDelivery")]
        public string CahsOnDelivery { get; set; }

        [JsonProperty("amountCash")]
        [JsonConverter(typeof(FluffyParseStringConverter))]
        public long AmountCash { get; set; }

        [JsonProperty("SecurePackage")]
        [JsonConverter(typeof(PurpleParseStringConverter))]
        public bool SecurePackage { get; set; }

        [JsonProperty("amountSecure")]
        [JsonConverter(typeof(FluffyParseStringConverter))]
        public long AmountSecure { get; set; }

        [JsonProperty("receivedId")]
        public string ReceivedId { get; set; }

        [JsonProperty("origin")]
        public EnviaOrigin EnviaOrigin { get; set; }

        [JsonProperty("destination")]
        public EnviaDestination EnviaDestination { get; set; }
    }

    public partial class EnviaDestination
    {
        [JsonProperty("receiver")]
        public string Receiver { get; set; }

        [JsonProperty("nameReceiver")]
        public string NameReceiver { get; set; }

        [JsonProperty("lastNameReceiver")]
        public string LastNameReceiver { get; set; }

        [JsonProperty("emailReceiver")]
        public string EmailReceiver { get; set; }

        [JsonProperty("phoneReceiver")]
        public string PhoneReceiver { get; set; }

        [JsonProperty("addressDestination")]
        public string AddressDestination { get; set; }

        [JsonProperty("numberDestination")]
        public string NumberDestination { get; set; }

        [JsonProperty("codePostalDestination")]
      
        public string CodePostalDestination { get; set; }

        [JsonProperty("country")]
        public string EnviaCountry { get; set; }
    }

    public partial class EnviaOrigin
    {
        [JsonProperty("sender")]
        public string Sender { get; set; }

        [JsonProperty("nameSender")]
        public string NameSender { get; set; }

        [JsonProperty("lastNameSender")]
        public string LastNameSender { get; set; }

        [JsonProperty("emailSender")]
        public string EmailSender { get; set; }

        [JsonProperty("phoneSender")]
        public string PhoneSender { get; set; }

        [JsonProperty("addressOrigin")]
        public string AddressOrigin { get; set; }

        [JsonProperty("numberOrigin")]
        public string NumberOrigin { get; set; }

        [JsonProperty("codePostalOrigin")]

        public string CodePostalOrigin { get; set; }

        [JsonProperty("country")]
        public string EnviaCountry { get; set; }
    }

    public partial class ClsEnvia99Minutos
    {
        public static ClsEnvia99Minutos FromJson(string json) => JsonConvert.DeserializeObject<ClsEnvia99Minutos>(json, Converter.Settings);
    }

    //public static class Serialize
    //{
    //    public static string ToJson(this ClsEnvia99Minutos self) => JsonConvert.SerializeObject(self, CreateLabel_ML.Converter.Settings);
    //}

    //internal static class Converter
    //{
    //    public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
    //    {
    //        MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
    //        DateParseHandling = DateParseHandling.None,
    //        Converters =
    //        {
    //            new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }
    //        },
    //    };
    //}

    internal class PurpleParseStringConverter : JsonConverter
    {
        public override bool CanConvert(Type t) => t == typeof(bool) || t == typeof(bool?);

        public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer)
        {
            if (reader.TokenType == JsonToken.Null) return null;
            var value = serializer.Deserialize<string>(reader);
            bool b;
            if (Boolean.TryParse(value, out b))
            {
                return b;
            }
            throw new Exception("Cannot unmarshal type bool");
        }

        public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer)
        {
            if (untypedValue == null)
            {
                serializer.Serialize(writer, null);
                return;
            }
            var value = (bool)untypedValue;
            var boolString = value ? "true" : "false";
            serializer.Serialize(writer, boolString);
            return;
        }

        public static readonly PurpleParseStringConverter Singleton = new PurpleParseStringConverter();
    }

    internal class FluffyParseStringConverter : JsonConverter
    {
        public override bool CanConvert(Type t) => t == typeof(long) || t == typeof(long?);

        public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer)
        {
            if (reader.TokenType == JsonToken.Null) return null;
            var value = serializer.Deserialize<string>(reader);
            long l;
            if (Int64.TryParse(value, out l))
            {
                return l;
            }
            throw new Exception("Cannot unmarshal type long");
        }

        public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer)
        {
            if (untypedValue == null)
            {
                serializer.Serialize(writer, null);
                return;
            }
            var value = (long)untypedValue;
            serializer.Serialize(writer, value.ToString());
            return;
        }

        public static readonly FluffyParseStringConverter Singleton = new FluffyParseStringConverter();
    }

