/**
  * @param array<string,mixed> $couponArray
  */
 private function createCouponFromArray(array $couponArray)
 {
     $coupon = new Coupon();
     $coupon->setCouponCode($couponArray['coupon_code']);
     $coupon->setCreatedAt(JsonDate::toDateTime($couponArray['created_at']));
     foreach ($couponArray['package_discounts'] as $packageDiscountArray) {
         $coupon->addPackageDiscount($this->createPackageDiscountFromArray($packageDiscountArray));
     }
     $coupon->setEndDate(CouponDate::toDateTime($couponArray['end_date']));
     $coupon->setNumUses($couponArray['max_uses']);
     $coupon->setNote($couponArray['note']);
     $coupon->setNumUses($couponArray['num_uses']);
     $coupon->setStartDate(CouponDate::toDateTime($couponArray['start_date']));
     $coupon->setSuspended($couponArray['suspended']);
     $coupon->setUpdatedAt(JsonDate::toDateTime($couponArray['updated_at']));
     $coupon->setBookId($couponArray['book_id']);
     return $coupon;
 }
 /**
  * @param CreateCoupon $createCoupon
  * @return string
  */
 public function serialize(DtoInterface $createCoupon, $format)
 {
     Assertion::same($format, 'json');
     Assertion::isInstanceOf($createCoupon, 'Matthias\\LeanpubApi\\Dto\\CreateCoupon');
     return json_encode(array('coupon_code' => $createCoupon->getCouponCode(), 'package_discounts_attributes' => array_map(array($this, 'serializePackageDiscount'), $createCoupon->getPackageDiscounts()), 'start_date' => CouponDate::fromDateTime($createCoupon->getStartDate()), 'end_date' => CouponDate::fromDateTime($createCoupon->getEndDate()), 'max_uses' => $createCoupon->getMaxUses(), 'note' => $createCoupon->getNote(), 'suspended' => $createCoupon->isSuspended()));
 }