/** * Generated by API Builder - https://www.apibuilder.io * Service version: 1.1.0 * User agent: apibuilder app.apibuilder.io/hbc/api-product-recommendations-lat/1.1.0/http4s_0_23 */ package com.hbc.api.product.recommendations.lat.v1.models { /** * Product price in USD * * @param was formatted price in USD * @param now formatted price in USD * @param onSale true if now price is < was price. Used to */ final case class Price( was: String, now: String, onSale: Boolean = false ) /** * @param rating customer review's rating * @param numReviews number of customers that reviewed the product */ final case class Recommendation( productId: String, productName: String, productUrl: String, productImageUrl: String, brandName: String, price: com.hbc.api.product.recommendations.lat.v1.models.Price, rating: _root_.scala.Option[Double] = None, numReviews: _root_.scala.Option[Long] = None ) final case class SimilarProductRecommendation( recommendations: Seq[com.hbc.api.product.recommendations.lat.v1.models.Recommendation] ) sealed trait SimilarProductContext extends _root_.scala.Product with _root_.scala.Serializable object SimilarProductContext { /** * PDP page. (Strict category match) */ case object Pdp extends SimilarProductContext { override def toString = "pdp" } /** * UNDEFINED captures values that are sent either in error or * that were added by the server after this library was * generated. We want to make it easy and obvious to users of * this library to handle this case gracefully. * * We use all CAPS for the variable name to avoid collisions * with the camel cased values above. */ final case class UNDEFINED(override val toString: String) extends SimilarProductContext /** * all returns a list of all the valid, known values. We use * lower case to avoid collisions with the camel cased values * above. */ val all: scala.List[SimilarProductContext] = scala.List(Pdp) private val byName: Map[String, SimilarProductContext] = all.map(x => x.toString.toLowerCase -> x).toMap def apply(value: String): SimilarProductContext = fromString(value).getOrElse(UNDEFINED(value)) def fromString(value: String): _root_.scala.Option[SimilarProductContext] = byName.get(value.toLowerCase) } } package com.hbc.api.product.recommendations.lat.v1.models { package object json { import io.circe.Decoder._ import io.circe.Encoder._ import scala.language.implicitConversions // See below - Make Scala 2.11 Either monadic import scala.util.Try import io.circe.{Json, JsonObject, Encoder, Decoder, DecodingFailure} import io.circe.syntax._ import com.hbc.api.product.recommendations.lat.v1.models.json._ // Make Scala 2.11 Either monadic private[v1] implicit def eitherOps[A,B](e: Either[A,B]) = cats.implicits.catsSyntaxEither(e) private[v1] implicit val decodeUUID: Decoder[_root_.java.util.UUID] = Decoder.decodeString.emapTry(str => Try(_root_.java.util.UUID.fromString(str))) private[v1] implicit val encodeUUID: Encoder[_root_.java.util.UUID] = Encoder.encodeString.contramap[_root_.java.util.UUID](uuid => uuid.toString) private[v1] implicit val decodeInstant: Decoder[_root_.java.time.Instant] = Decoder.decodeString.emapTry(str => Try(_root_.java.time.OffsetDateTime.parse(str).toInstant)) private[v1] implicit val encodeInstant: Encoder[_root_.java.time.Instant] = Encoder.encodeString.contramap[_root_.java.time.Instant](_.toString) private[v1] implicit val decodeLocalDate: Decoder[_root_.java.time.LocalDate] = Decoder.decodeString.emapTry(str => Try(_root_.java.time.LocalDate.parse(str))) private[v1] implicit val encodeLocalDate: Encoder[_root_.java.time.LocalDate] = Encoder.encodeString.contramap[_root_.java.time.LocalDate](_.toString) implicit val jsonDecoderApiProductRecommendationsLatSimilarProductContext: Decoder[com.hbc.api.product.recommendations.lat.v1.models.SimilarProductContext] = Decoder.decodeString.map(com.hbc.api.product.recommendations.lat.v1.models.SimilarProductContext(_)) implicit val jsonEncoderApiProductRecommendationsLatSimilarProductContext: Encoder[com.hbc.api.product.recommendations.lat.v1.models.SimilarProductContext] = Encoder.encodeString.contramap[com.hbc.api.product.recommendations.lat.v1.models.SimilarProductContext](_.toString) implicit def decodeApiProductRecommendationsLatPrice: Decoder[Price] = Decoder.instance { c => for { was <- c.downField("was").as[String] now <- c.downField("now").as[String] onSale <- c.downField("onSale").as[Boolean] } yield { Price( was = was, now = now, onSale = onSale ) } } implicit def encodeApiProductRecommendationsLatPrice: Encoder[Price] = Encoder.instance { t => Json.fromFields(Seq( Some("was" -> t.was.asJson), Some("now" -> t.now.asJson), Some("onSale" -> t.onSale.asJson) ).flatten) } implicit def decodeApiProductRecommendationsLatRecommendation: Decoder[Recommendation] = Decoder.instance { c => for { productId <- c.downField("productId").as[String] productName <- c.downField("productName").as[String] productUrl <- c.downField("productUrl").as[String] productImageUrl <- c.downField("productImageUrl").as[String] brandName <- c.downField("brandName").as[String] price <- c.downField("price").as[com.hbc.api.product.recommendations.lat.v1.models.Price] rating <- c.downField("rating").as[Option[Double]] numReviews <- c.downField("numReviews").as[Option[Long]] } yield { Recommendation( productId = productId, productName = productName, productUrl = productUrl, productImageUrl = productImageUrl, brandName = brandName, price = price, rating = rating, numReviews = numReviews ) } } implicit def encodeApiProductRecommendationsLatRecommendation: Encoder[Recommendation] = Encoder.instance { t => Json.fromFields(Seq( Some("productId" -> t.productId.asJson), Some("productName" -> t.productName.asJson), Some("productUrl" -> t.productUrl.asJson), Some("productImageUrl" -> t.productImageUrl.asJson), Some("brandName" -> t.brandName.asJson), Some("price" -> t.price.asJson), t.rating.map(t => "rating" -> t.asJson), t.numReviews.map(t => "numReviews" -> t.asJson) ).flatten) } implicit def decodeApiProductRecommendationsLatSimilarProductRecommendation: Decoder[SimilarProductRecommendation] = Decoder.instance { c => for { recommendations <- c.downField("recommendations").as[Seq[com.hbc.api.product.recommendations.lat.v1.models.Recommendation]] } yield { SimilarProductRecommendation( recommendations = recommendations ) } } implicit def encodeApiProductRecommendationsLatSimilarProductRecommendation: Encoder[SimilarProductRecommendation] = Encoder.instance { t => Json.fromFields(Seq( Some("recommendations" -> t.recommendations.asJson) ).flatten) } } }