def fromNoPriceIncreaseEstimationResult()

in lambda/src/main/scala/pricemigrationengine/model/CohortItem.scala [57:98]


  def fromNoPriceIncreaseEstimationResult(result: EstimationData): UIO[CohortItem] =
    fromSuccessfulEstimationResult(result).map(_.copy(processingStage = NoPriceIncrease))

  def fromFailedEstimationResult(result: FailedEstimationResult): CohortItem =
    CohortItem(result.subscriptionNumber, EstimationFailed)

  def fromCancelledEstimationResult(result: CancelledEstimationResult, reason: String): CohortItem =
    CohortItem(result.subscriptionNumber, processingStage = Cancelled, cancellationReason = Some(reason))

  def fromSuccessfulAmendmentResult(result: SuccessfulAmendmentResult): CohortItem =
    CohortItem(
      result.subscriptionNumber,
      processingStage = AmendmentComplete,
      startDate = Some(result.startDate),
      newPrice = Some(result.newPrice),
      newSubscriptionId = Some(result.newSubscriptionId),
      whenAmendmentDone = Some(result.whenDone)
    )

  def fromCancelledAmendmentResult(result: CancelledAmendmentResult, reason: String): CohortItem =
    CohortItem(
      result.subscriptionNumber,
      processingStage = Cancelled,
      cancellationReason = Some(reason)
    )

  def fromExpiringSubscriptionResult(result: ExpiringSubscriptionResult): CohortItem =
    CohortItem(result.subscriptionNumber, Cancelled)

  def isProcessable(item: CohortItem, today: LocalDate): Boolean = {
    // This function return a boolean indicating whether the item is processable
    // defined as either doNotProcessUntil is None or is a date equal to today or in the past.
    (item.processingStage != DoNotProcessUntil) || {
      item.doNotProcessUntil match {
        case None =>
          throw new Exception(
            s"(error: 588b7698) cohort item: ${item} is in DoNotProcessUntil stage but doesn't have a doNotProcessUntil attribute"
          )
        case Some(date) => date == today || today.isAfter(date)
      }
    }
  }