def fromCatalog()

in handlers/new-product-api/src/main/scala/com/gu/newproduct/api/productcatalog/WireModel.scala [149:233]


    def fromCatalog(catalog: Map[PlanId, Plan]) = {

      def wirePlanForPlanId(planId: PlanId): WirePlanInfo = {
        val plan = catalog(planId)
        WirePlanInfo.fromPlan(plan)
      }

      val voucherProduct = WireProduct(
        label = "Voucher",
        plans = PlanId.enabledVoucherPlans.map(wirePlanForPlanId),
        enabledForDeliveryCountries = None,
      )

      val supporterPlusProduct = WireProduct(
        label = "Supporter Plus",
        plans = PlanId.enabledSupporterPlusPlans.map(wirePlanForPlanId),
        enabledForDeliveryCountries = None,
      )

      val contributionProduct = WireProduct(
        label = "Contribution",
        plans = PlanId.enabledContributionPlans.map(wirePlanForPlanId),
        enabledForDeliveryCountries = None,
      )

      val homeDeliveryProduct = WireProduct(
        label = "Home Delivery",
        plans = PlanId.enabledHomeDeliveryPlans.map(wirePlanForPlanId),
        enabledForDeliveryCountries = None,
      )

      val digipackProduct = WireProduct(
        label = "Digital Pack",
        plans = PlanId.enabledDigipackPlans.map(wirePlanForPlanId),
        enabledForDeliveryCountries = None,
      )

      val guardianWeeklyDomestic = WireProduct(
        label = "Guardian Weekly - Domestic",
        plans = PlanId.enabledGuardianWeeklyDomesticPlans.map(wirePlanForPlanId),
        enabledForDeliveryCountries = Some(GuardianWeeklyAddressValidator.domesticCountries.map(_.name)),
      )

      val guardianWeeklyROW = WireProduct(
        label = "Guardian Weekly - ROW",
        plans = PlanId.enabledGuardianWeeklyROWPlans.map(wirePlanForPlanId),
        enabledForDeliveryCountries = Some(CountryGroup.RestOfTheWorld.countries.map(_.name)),
      )

      val digitalVoucher = WireProduct(
        label = "Subscription Card",
        plans = PlanId.enabledDigitalVoucherPlans.map(wirePlanForPlanId),
        enabledForDeliveryCountries = Some(List(Country.UK.name)),
      )

      val nationalDelivery = WireProduct(
        label = "National Delivery",
        plans = PlanId.enabledNationalDeliveryPlans.map(wirePlanForPlanId),
        enabledForDeliveryCountries = Some(List(Country.UK.name)),
      )

      val tierThree = WireProduct(
        label = "Tier Three",
        plans = PlanId.enabledTierThreePlans.map(wirePlanForPlanId),
        enabledForDeliveryCountries = Some(List(Country.UK.name)),
      )

      val availableProductsAndPlans = {
        val unfiltered = List(
          supporterPlusProduct,
          contributionProduct,
          voucherProduct,
          homeDeliveryProduct,
          digipackProduct,
          guardianWeeklyDomestic,
          guardianWeeklyROW,
          digitalVoucher,
          nationalDelivery,
          tierThree,
        )
        unfiltered.filter(_.plans.nonEmpty)
      }

      WireCatalog(availableProductsAndPlans)
    }