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

alloy.proto.ReservedFieldsDefinition.scala Maven / Gradle / Ivy

There is a newer version: 0.19.0-41-91762fb
Show newest version
package alloy.proto

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

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

  object project {
    def name: Option[String] = ReservedFieldsDefinition.NameCase.alt.project.lift(self).map(_.name)
    def number: Option[Int] = ReservedFieldsDefinition.NumberCase.alt.project.lift(self).map(_.number)
    def range: Option[Range] = ReservedFieldsDefinition.RangeCase.alt.project.lift(self).map(_.range)
  }

  def accept[A](visitor: ReservedFieldsDefinition.Visitor[A]): A = this match {
    case value: ReservedFieldsDefinition.NameCase => visitor.name(value.name)
    case value: ReservedFieldsDefinition.NumberCase => visitor.number(value.number)
    case value: ReservedFieldsDefinition.RangeCase => visitor.range(value.range)
  }
}
object ReservedFieldsDefinition extends ShapeTag.Companion[ReservedFieldsDefinition] {

  def name(name: String): ReservedFieldsDefinition = NameCase(name)
  def number(number: Int): ReservedFieldsDefinition = NumberCase(number)
  def range(range: Range): ReservedFieldsDefinition = RangeCase(range)

  val id: ShapeId = ShapeId("alloy.proto", "ReservedFieldsDefinition")

  val hints: Hints = Hints.empty

  final case class NameCase(name: String) extends ReservedFieldsDefinition { final def $ordinal: Int = 0 }
  final case class NumberCase(number: Int) extends ReservedFieldsDefinition { final def $ordinal: Int = 1 }
  final case class RangeCase(range: Range) extends ReservedFieldsDefinition { final def $ordinal: Int = 2 }

  object NameCase {
    val hints: Hints = Hints.empty
    val schema: Schema[ReservedFieldsDefinition.NameCase] = bijection(string.addHints(hints), ReservedFieldsDefinition.NameCase(_), _.name)
    val alt = schema.oneOf[ReservedFieldsDefinition]("name")
  }
  object NumberCase {
    val hints: Hints = Hints.empty
    val schema: Schema[ReservedFieldsDefinition.NumberCase] = bijection(int.addHints(hints), ReservedFieldsDefinition.NumberCase(_), _.number)
    val alt = schema.oneOf[ReservedFieldsDefinition]("number")
  }
  object RangeCase {
    val hints: Hints = Hints.empty
    val schema: Schema[ReservedFieldsDefinition.RangeCase] = bijection(Range.schema.addHints(hints), ReservedFieldsDefinition.RangeCase(_), _.range)
    val alt = schema.oneOf[ReservedFieldsDefinition]("range")
  }

  trait Visitor[A] {
    def name(value: String): A
    def number(value: Int): A
    def range(value: Range): A
  }

  object Visitor {
    trait Default[A] extends Visitor[A] {
      def default: A
      def name(value: String): A = default
      def number(value: Int): A = default
      def range(value: Range): A = default
    }
  }

  implicit val schema: Schema[ReservedFieldsDefinition] = union(
    ReservedFieldsDefinition.NameCase.alt,
    ReservedFieldsDefinition.NumberCase.alt,
    ReservedFieldsDefinition.RangeCase.alt,
  ){
    _.$ordinal
  }.withId(id).addHints(hints)
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy