FeatureGateConfig.fromJson constructor

FeatureGateConfig.fromJson(
  1. Map<String, dynamic> json
)

Deserializes a config from a JSON map.

Implementation

factory FeatureGateConfig.fromJson(Map<String, dynamic> json) {
  final gateMap = <FeatureGate, bool>{};
  final rawGates = json['gates'] as Map<String, dynamic>? ?? {};
  for (final entry in rawGates.entries) {
    final gate = FeatureGate.values.where((g) => g.name == entry.key);
    if (gate.isNotEmpty) {
      gateMap[gate.first] = entry.value as bool;
    }
  }
  return FeatureGateConfig(
    gates: gateMap,
    organizationId: json['organizationId'] as String?,
    plan: Plan.values.firstWhere(
      (p) => p.name == json['plan'],
      orElse: () => Plan.free,
    ),
    evaluatedAt: DateTime.parse(json['evaluatedAt'] as String),
  );
}