fromJson static method

Coupon? fromJson(
  1. dynamic value
)

Returns a new Coupon instance and imports its values from value if it's a Map, null otherwise.

Implementation

// ignore: prefer_constructors_over_static_methods
static Coupon? fromJson(dynamic value) {
  if (value is Map) {
    final json = value.cast<String, dynamic>();

    // Ensure that the map contains the required keys.
    // Note 1: the values aren't checked for validity beyond being non-null.
    // Note 2: this code is stripped in release mode!
    assert(() {
      requiredKeys.forEach((key) {
        assert(json.containsKey(key), 'Required key "Coupon[$key]" is missing from JSON.');
        assert(json[key] != null, 'Required key "Coupon[$key]" has a null value in JSON.');
      });
      return true;
    }());

    return Coupon(
      id: mapValueOfType<int>(json, r'id'),
      code: mapValueOfType<String>(json, r'code'),
      discountType: DiscountTypeEnum.fromJson(json[r'discount_type']),
      description: mapValueOfType<String>(json, r'description'),
      lessonDiscount: mapValueOfType<double>(json, r'lesson_discount'),
      applyStudent: mapValueOfType<int>(json, r'apply_student'),
      applyTutor: mapValueOfType<int>(json, r'apply_tutor'),
      startAt: mapDateTime(json, r'start_at', r''),
      endAt: mapDateTime(json, r'end_at', r''),
      originalUnitPriceInCents: mapValueOfType<int>(json, r'original_unit_price_in_cents'),
      presentUnitPriceInCents: mapValueOfType<int>(json, r'present_unit_price_in_cents'),
      originalAmountInCents: mapValueOfType<int>(json, r'original_amount_in_cents'),
      presentAmountInCents: mapValueOfType<int>(json, r'present_amount_in_cents'),
      eligibleMinBookingNumber: mapValueOfType<int>(json, r'eligible_min_booking_number'),
    );
  }
  return null;
}