BillingData: Upgrade GetSelection()
This commit is contained in:
@ -146,7 +146,12 @@ namespace Elwig.Helpers.Billing {
|
|||||||
return dict;
|
return dict;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static Dictionary<string, JsonValue> GetSelection(JsonObject data, IEnumerable<string> attributeVariants) {
|
protected static Dictionary<string, JsonValue> GetSelection(JsonNode value, IEnumerable<string> attributeVariants) {
|
||||||
|
if (value is JsonValue flatRate) {
|
||||||
|
return attributeVariants.ToDictionary(e => e, _ => flatRate);
|
||||||
|
} if (value is not JsonObject data) {
|
||||||
|
throw new InvalidOperationException();
|
||||||
|
}
|
||||||
Dictionary<string, JsonValue> dict;
|
Dictionary<string, JsonValue> dict;
|
||||||
if (data["default"] is JsonValue def) {
|
if (data["default"] is JsonValue def) {
|
||||||
dict = attributeVariants.ToDictionary(e => e, _ => def);
|
dict = attributeVariants.ToDictionary(e => e, _ => def);
|
||||||
|
@ -25,17 +25,12 @@ namespace Elwig.Helpers.Billing {
|
|||||||
return new(ParseJson(json), attributeVariants);
|
return new(ParseJson(json), attributeVariants);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Dictionary<string, Curve> GetData(JsonObject data) {
|
private Dictionary<string, Curve> GetData(JsonNode data) {
|
||||||
return GetSelection(data, AttributeVariants).ToDictionary(e => e.Key, e => LookupCurve(e.Value));
|
return GetSelection(data, AttributeVariants).ToDictionary(e => e.Key, e => LookupCurve(e.Value));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Dictionary<string, Curve> GetPaymentData() {
|
protected Dictionary<string, Curve> GetPaymentData() {
|
||||||
var p = GetPaymentEntry();
|
return GetData(GetPaymentEntry());
|
||||||
if (p is JsonValue val) {
|
|
||||||
var c = LookupCurve(val);
|
|
||||||
return AttributeVariants.ToDictionary(e => e, _ => c);
|
|
||||||
}
|
|
||||||
return GetData(p?.AsObject() ?? throw new InvalidOperationException());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Dictionary<string, Curve> GetQualityData() {
|
protected Dictionary<string, Curve> GetQualityData() {
|
||||||
@ -44,14 +39,7 @@ namespace Elwig.Helpers.Billing {
|
|||||||
if (q == null) return dict;
|
if (q == null) return dict;
|
||||||
|
|
||||||
foreach (var (qualid, data) in q) {
|
foreach (var (qualid, data) in q) {
|
||||||
Dictionary<string, Curve> qualDict;
|
foreach (var (idx, d) in GetData(data ?? throw new InvalidOperationException())) {
|
||||||
if (data is JsonValue val) {
|
|
||||||
var c = LookupCurve(val);
|
|
||||||
qualDict = AttributeVariants.ToDictionary(e => e, _ => c);
|
|
||||||
} else {
|
|
||||||
qualDict = GetData(data?.AsObject() ?? throw new InvalidOperationException());
|
|
||||||
}
|
|
||||||
foreach (var (idx, d) in qualDict) {
|
|
||||||
dict[$"{qualid}/{idx}"] = d;
|
dict[$"{qualid}/{idx}"] = d;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user