All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.quafadas.dairect.MessageOnThread.scala Maven / Gradle / Ivy

The newest version!
package io.github.quafadas.dairect

import smithy4s.Hints
import smithy4s.Schema
import smithy4s.ShapeId
import smithy4s.ShapeTag
import smithy4s.schema.Schema.bijection
import smithy4s.schema.Schema.string
import smithy4s.schema.Schema.union

sealed trait MessageOnThread extends scala.Product with scala.Serializable { self =>
  @inline final def widen: MessageOnThread = this
  def $ordinal: Int

  object project {
    def str: Option[String] = MessageOnThread.StrCase.alt.project.lift(self).map(_.str)
    def array: Option[List[MessageToSend]] = MessageOnThread.ArrayCase.alt.project.lift(self).map(_.array)
  }

  def accept[A](visitor: MessageOnThread.Visitor[A]): A = this match {
    case value: MessageOnThread.StrCase => visitor.str(value.str)
    case value: MessageOnThread.ArrayCase => visitor.array(value.array)
  }
}
object MessageOnThread extends ShapeTag.Companion[MessageOnThread] {

  def str(str: String): MessageOnThread = StrCase(str)
  def array(array: List[MessageToSend]): MessageOnThread = ArrayCase(array)

  val id: ShapeId = ShapeId("io.github.quafadas.dairect", "MessageOnThread")

  val hints: Hints = Hints(
    alloy.Untagged(),
  ).lazily

  final case class StrCase(str: String) extends MessageOnThread { final def $ordinal: Int = 0 }
  final case class ArrayCase(array: List[MessageToSend]) extends MessageOnThread { final def $ordinal: Int = 1 }

  object StrCase {
    val hints: Hints = Hints.empty
    val schema: Schema[MessageOnThread.StrCase] = bijection(string.addHints(hints), MessageOnThread.StrCase(_), _.str)
    val alt = schema.oneOf[MessageOnThread]("str")
  }
  object ArrayCase {
    val hints: Hints = Hints.empty
    val schema: Schema[MessageOnThread.ArrayCase] = bijection(MessageToSendList.underlyingSchema.addHints(hints), MessageOnThread.ArrayCase(_), _.array)
    val alt = schema.oneOf[MessageOnThread]("array")
  }

  trait Visitor[A] {
    def str(value: String): A
    def array(value: List[MessageToSend]): A
  }

  object Visitor {
    trait Default[A] extends Visitor[A] {
      def default: A
      def str(value: String): A = default
      def array(value: List[MessageToSend]): A = default
    }
  }

  implicit val schema: Schema[MessageOnThread] = union(
    MessageOnThread.StrCase.alt,
    MessageOnThread.ArrayCase.alt,
  ){
    _.$ordinal
  }.withId(id).addHints(hints)
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy