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

io.github.quafadas.dairect.MessageContent.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.union

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

  object project {
    def text: Option[Text] = MessageContent.TextCase.alt.project.lift(self).map(_.text)
    def image_file: Option[ImageFile] = MessageContent.Image_fileCase.alt.project.lift(self).map(_.image_file)
    def image_url: Option[ImageUrl] = MessageContent.Image_urlCase.alt.project.lift(self).map(_.image_url)
  }

  def accept[A](visitor: MessageContent.Visitor[A]): A = this match {
    case value: MessageContent.TextCase => visitor.text(value.text)
    case value: MessageContent.Image_fileCase => visitor.image_file(value.image_file)
    case value: MessageContent.Image_urlCase => visitor.image_url(value.image_url)
  }
}
object MessageContent extends ShapeTag.Companion[MessageContent] {

  def text(text: Text): MessageContent = TextCase(text)
  def image_file(image_file: ImageFile): MessageContent = Image_fileCase(image_file)
  def image_url(image_url: ImageUrl): MessageContent = Image_urlCase(image_url)

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

  val hints: Hints = Hints(
    alloy.Discriminated("type"),
  ).lazily

  final case class TextCase(text: Text) extends MessageContent { final def $ordinal: Int = 0 }
  final case class Image_fileCase(image_file: ImageFile) extends MessageContent { final def $ordinal: Int = 1 }
  final case class Image_urlCase(image_url: ImageUrl) extends MessageContent { final def $ordinal: Int = 2 }

  object TextCase {
    val hints: Hints = Hints.empty
    val schema: Schema[MessageContent.TextCase] = bijection(Text.schema.addHints(hints), MessageContent.TextCase(_), _.text)
    val alt = schema.oneOf[MessageContent]("text")
  }
  object Image_fileCase {
    val hints: Hints = Hints.empty
    val schema: Schema[MessageContent.Image_fileCase] = bijection(ImageFile.schema.addHints(hints), MessageContent.Image_fileCase(_), _.image_file)
    val alt = schema.oneOf[MessageContent]("image_file")
  }
  object Image_urlCase {
    val hints: Hints = Hints.empty
    val schema: Schema[MessageContent.Image_urlCase] = bijection(ImageUrl.schema.addHints(hints), MessageContent.Image_urlCase(_), _.image_url)
    val alt = schema.oneOf[MessageContent]("image_url")
  }

  trait Visitor[A] {
    def text(value: Text): A
    def image_file(value: ImageFile): A
    def image_url(value: ImageUrl): A
  }

  object Visitor {
    trait Default[A] extends Visitor[A] {
      def default: A
      def text(value: Text): A = default
      def image_file(value: ImageFile): A = default
      def image_url(value: ImageUrl): A = default
    }
  }

  implicit val schema: Schema[MessageContent] = union(
    MessageContent.TextCase.alt,
    MessageContent.Image_fileCase.alt,
    MessageContent.Image_urlCase.alt,
  ){
    _.$ordinal
  }.withId(id).addHints(hints)
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy