def subscriptionToBatchId()

in lambda/src/main/scala/pricemigrationengine/migrations/Newspaper2024Migration/Estimation.scala [126:154]


  def subscriptionToBatchId(subscription: ZuoraSubscription): Either[String, Newspaper2024BatchId] = {

    def ratePlanChargesToBatchId(list: List[ZuoraRatePlanCharge]): Either[String, Newspaper2024BatchId] = {
      list match {
        case Nil => Left(s"Could not extract a rate plan charge for subscription: ${subscription.subscriptionNumber}")
        case rpc :: _ => {
          val monthIndex = rpc.chargedThroughDate.getOrElse(LocalDate.of(2024, 1, 1)).getDayOfMonth
          if (monthIndex <= 20) {
            Right(MonthliesPart2)
          } else {
            Right(MonthliesPart1)
          }
        }
      }
    }

    for {
      subscriptionData <- subscriptionToSubscriptionData2024(subscription)
      batchId <- {
        subscriptionData.billingPeriod match {
          case Monthly => {
            val ratePlan = subscriptionData.ratePlan
            ratePlanChargesToBatchId(ratePlan.ratePlanCharges)
          }
          case _ => Right(MoreThanMonthlies)
        }
      }
    } yield batchId
  }