internal ExchangeResponseProperties(string sessionId, PurchasePrice netPayable, PurchasePrice refundsTotal, PurchasePrice purchasesTotal, IReadOnlyList <ReservationToPurchaseExchange> reservationsToPurchase, IReadOnlyList <ReservationToReturnForExchange> reservationsToExchange, ExchangePolicyErrors policyResult)
 {
     SessionId              = sessionId;
     NetPayable             = netPayable;
     RefundsTotal           = refundsTotal;
     PurchasesTotal         = purchasesTotal;
     ReservationsToPurchase = reservationsToPurchase;
     ReservationsToExchange = reservationsToExchange;
     PolicyResult           = policyResult;
 }
        internal static ExchangeResponseProperties DeserializeExchangeResponseProperties(JsonElement element)
        {
            Optional <string>        sessionId      = default;
            Optional <PurchasePrice> netPayable     = default;
            Optional <PurchasePrice> refundsTotal   = default;
            Optional <PurchasePrice> purchasesTotal = default;
            Optional <IReadOnlyList <ReservationToPurchaseExchange> >  reservationsToPurchase = default;
            Optional <IReadOnlyList <ReservationToReturnForExchange> > reservationsToExchange = default;
            Optional <ExchangePolicyErrors> policyResult = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("sessionId"))
                {
                    sessionId = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("netPayable"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    netPayable = PurchasePrice.DeserializePurchasePrice(property.Value);
                    continue;
                }
                if (property.NameEquals("refundsTotal"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    refundsTotal = PurchasePrice.DeserializePurchasePrice(property.Value);
                    continue;
                }
                if (property.NameEquals("purchasesTotal"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    purchasesTotal = PurchasePrice.DeserializePurchasePrice(property.Value);
                    continue;
                }
                if (property.NameEquals("reservationsToPurchase"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <ReservationToPurchaseExchange> array = new List <ReservationToPurchaseExchange>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(ReservationToPurchaseExchange.DeserializeReservationToPurchaseExchange(item));
                    }
                    reservationsToPurchase = array;
                    continue;
                }
                if (property.NameEquals("reservationsToExchange"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <ReservationToReturnForExchange> array = new List <ReservationToReturnForExchange>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(ReservationToReturnForExchange.DeserializeReservationToReturnForExchange(item));
                    }
                    reservationsToExchange = array;
                    continue;
                }
                if (property.NameEquals("policyResult"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    policyResult = ExchangePolicyErrors.DeserializeExchangePolicyErrors(property.Value);
                    continue;
                }
            }
            return(new ExchangeResponseProperties(sessionId.Value, netPayable.Value, refundsTotal.Value, purchasesTotal.Value, Optional.ToList(reservationsToPurchase), Optional.ToList(reservationsToExchange), policyResult.Value));
        }