/** * Generated by API Builder - https://www.apibuilder.io * Service version: 1.1.0 * User agent: apibuilder app.apibuilder.io/paintbatch-com/paint-batch-optimizer/1.1.0/http4s_0_23 */ package com.paintbatch.models { /** * range of customers preferences to choose from * * @param paints paints the customer would be satisfied with */ final case class Demand( paints: Seq[com.paintbatch.models.Paint] ) /** * health of the service * * @param status the health status of the service */ final case class Healthcheck( status: com.paintbatch.models.Status ) /** * paint batch optimizer request * * @param colors number of different colours demanded by paint factory * @param customers number of customers * @param demands customers paint demands */ final case class OptimizeRequest( colors: Int, customers: Int, demands: Seq[com.paintbatch.models.Demand] ) /** * paint and its sheen * * @param id paint identifier * @param sheen sheen of the paint */ final case class Paint( id: Int, sheen: com.paintbatch.models.Sheen ) /** * A simple human-readable error */ final case class ReadableError( text: String ) /** * available paint sheens */ sealed trait Sheen extends _root_.scala.Product with _root_.scala.Serializable object Sheen { /** * matte sheen costs more than gloss */ case object Matte extends Sheen { override def toString = "M" } /** * gloss sheen costs less than matte */ case object Gloss extends Sheen { override def toString = "G" } /** * 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 Sheen /** * 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[Sheen] = scala.List(Matte, Gloss) private val byName: Map[String, Sheen] = all.map(x => x.toString.toLowerCase -> x).toMap def apply(value: String): Sheen = fromString(value).getOrElse(UNDEFINED(value)) def fromString(value: String): _root_.scala.Option[Sheen] = byName.get(value.toLowerCase) } /** * health of the service */ sealed trait Status extends _root_.scala.Product with _root_.scala.Serializable object Status { /** * represents the service is live and accepting traffic */ case object Ok extends Status { override def toString = "ok" } /** * 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 Status /** * 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[Status] = scala.List(Ok) private val byName: Map[String, Status] = all.map(x => x.toString.toLowerCase -> x).toMap def apply(value: String): Status = fromString(value).getOrElse(UNDEFINED(value)) def fromString(value: String): _root_.scala.Option[Status] = byName.get(value.toLowerCase) } } package com.paintbatch.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.paintbatch.models.json._ // Make Scala 2.11 Either monadic private[paintbatch] implicit def eitherOps[A,B](e: Either[A,B]) = cats.implicits.catsSyntaxEither(e) private[paintbatch] implicit val decodeUUID: Decoder[_root_.java.util.UUID] = Decoder.decodeString.emapTry(str => Try(_root_.java.util.UUID.fromString(str))) private[paintbatch] implicit val encodeUUID: Encoder[_root_.java.util.UUID] = Encoder.encodeString.contramap[_root_.java.util.UUID](uuid => uuid.toString) private[paintbatch] implicit val decodeInstant: Decoder[_root_.java.time.Instant] = Decoder.decodeString.emapTry(str => Try(_root_.java.time.OffsetDateTime.parse(str).toInstant)) private[paintbatch] implicit val encodeInstant: Encoder[_root_.java.time.Instant] = Encoder.encodeString.contramap[_root_.java.time.Instant](_.toString) private[paintbatch] implicit val decodeLocalDate: Decoder[_root_.java.time.LocalDate] = Decoder.decodeString.emapTry(str => Try(_root_.java.time.LocalDate.parse(str))) private[paintbatch] implicit val encodeLocalDate: Encoder[_root_.java.time.LocalDate] = Encoder.encodeString.contramap[_root_.java.time.LocalDate](_.toString) implicit val jsonDecoderPaintBatchOptimizerSheen: Decoder[com.paintbatch.models.Sheen] = Decoder.decodeString.map(com.paintbatch.models.Sheen(_)) implicit val jsonEncoderPaintBatchOptimizerSheen: Encoder[com.paintbatch.models.Sheen] = Encoder.encodeString.contramap[com.paintbatch.models.Sheen](_.toString) implicit val jsonDecoderPaintBatchOptimizerStatus: Decoder[com.paintbatch.models.Status] = Decoder.decodeString.map(com.paintbatch.models.Status(_)) implicit val jsonEncoderPaintBatchOptimizerStatus: Encoder[com.paintbatch.models.Status] = Encoder.encodeString.contramap[com.paintbatch.models.Status](_.toString) implicit def decodePaintBatchOptimizerDemand: Decoder[Demand] = Decoder.instance { c => for { paints <- c.downField("paints").as[Seq[com.paintbatch.models.Paint]] } yield { Demand( paints = paints ) } } implicit def encodePaintBatchOptimizerDemand: Encoder[Demand] = Encoder.instance { t => Json.fromFields(Seq( Some("paints" -> t.paints.asJson) ).flatten) } implicit def decodePaintBatchOptimizerHealthcheck: Decoder[Healthcheck] = Decoder.instance { c => for { status <- c.downField("status").as[com.paintbatch.models.Status] } yield { Healthcheck( status = status ) } } implicit def encodePaintBatchOptimizerHealthcheck: Encoder[Healthcheck] = Encoder.instance { t => Json.fromFields(Seq( Some("status" -> t.status.asJson) ).flatten) } implicit def decodePaintBatchOptimizerOptimizeRequest: Decoder[OptimizeRequest] = Decoder.instance { c => for { colors <- c.downField("colors").as[Int] customers <- c.downField("customers").as[Int] demands <- c.downField("demands").as[Seq[com.paintbatch.models.Demand]] } yield { OptimizeRequest( colors = colors, customers = customers, demands = demands ) } } implicit def encodePaintBatchOptimizerOptimizeRequest: Encoder[OptimizeRequest] = Encoder.instance { t => Json.fromFields(Seq( Some("colors" -> t.colors.asJson), Some("customers" -> t.customers.asJson), Some("demands" -> t.demands.asJson) ).flatten) } implicit def decodePaintBatchOptimizerPaint: Decoder[Paint] = Decoder.instance { c => for { id <- c.downField("id").as[Int] sheen <- c.downField("sheen").as[com.paintbatch.models.Sheen] } yield { Paint( id = id, sheen = sheen ) } } implicit def encodePaintBatchOptimizerPaint: Encoder[Paint] = Encoder.instance { t => Json.fromFields(Seq( Some("id" -> t.id.asJson), Some("sheen" -> t.sheen.asJson) ).flatten) } implicit def decodePaintBatchOptimizerReadableError: Decoder[ReadableError] = Decoder.instance { c => for { text <- c.downField("text").as[String] } yield { ReadableError( text = text ) } } implicit def encodePaintBatchOptimizerReadableError: Encoder[ReadableError] = Encoder.instance { t => Json.fromFields(Seq( Some("text" -> t.text.asJson) ).flatten) } } }