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

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

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 Annotation extends scala.Product with scala.Serializable { self =>
  @inline final def widen: Annotation = this
  def $ordinal: Int

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

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

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

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

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

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

  object TextCase {
    val hints: Hints = Hints.empty
    val schema: Schema[Annotation.TextCase] = bijection(Text.schema.addHints(hints), Annotation.TextCase(_), _.text)
    val alt = schema.oneOf[Annotation]("text")
  }
  object Image_fileCase {
    val hints: Hints = Hints.empty
    val schema: Schema[Annotation.Image_fileCase] = bijection(ImageFile.schema.addHints(hints), Annotation.Image_fileCase(_), _.image_file)
    val alt = schema.oneOf[Annotation]("image_file")
  }
  object Image_urlCase {
    val hints: Hints = Hints.empty
    val schema: Schema[Annotation.Image_urlCase] = bijection(ImageUrl.schema.addHints(hints), Annotation.Image_urlCase(_), _.image_url)
    val alt = schema.oneOf[Annotation]("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[Annotation] = union(
    Annotation.TextCase.alt,
    Annotation.Image_fileCase.alt,
    Annotation.Image_urlCase.alt,
  ){
    _.$ordinal
  }.withId(id).addHints(hints)
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy