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

io.k8s.apimachinery.pkg.apis.meta.v1.StatusDetails.scala Maven / Gradle / Ivy

package io.k8s.apimachinery.pkg.apis.meta.v1

import dev.hnaderi.k8s.utils._

/** StatusDetails is a set of additional properties that MAY be set by the server to provide additional information about a response. The Reason field of a Status object defines what attributes will be set. Clients must ignore fields that do not match the defined type of each attribute, and should assume that any attribute may be empty, invalid, or under defined. */
final case class StatusDetails(
  name : Option[String] = None,
  causes : Option[Seq[io.k8s.apimachinery.pkg.apis.meta.v1.StatusCause]] = None,
  uid : Option[String] = None,
  kind : Option[String] = None,
  retryAfterSeconds : Option[Int] = None,
  group : Option[String] = None
) {

  /** Returns a new data with name set to new value */
  def withName(value: String) : StatusDetails = copy(name = Some(value))
  /** if name has a value, transforms to the result of function*/
  def mapName(f: String => String) : StatusDetails = copy(name = name.map(f))

  /** Returns a new data with causes set to new value */
  def withCauses(value: Seq[io.k8s.apimachinery.pkg.apis.meta.v1.StatusCause]) : StatusDetails = copy(causes = Some(value))
  /** Appends new values to causes */
  def addCauses(newValues: io.k8s.apimachinery.pkg.apis.meta.v1.StatusCause*) : StatusDetails = copy(causes = Some(causes.fold(newValues)(_ ++ newValues)))
  /** if causes has a value, transforms to the result of function*/
  def mapCauses(f: Seq[io.k8s.apimachinery.pkg.apis.meta.v1.StatusCause] => Seq[io.k8s.apimachinery.pkg.apis.meta.v1.StatusCause]) : StatusDetails = copy(causes = causes.map(f))

  /** Returns a new data with uid set to new value */
  def withUid(value: String) : StatusDetails = copy(uid = Some(value))
  /** if uid has a value, transforms to the result of function*/
  def mapUid(f: String => String) : StatusDetails = copy(uid = uid.map(f))

  /** Returns a new data with kind set to new value */
  def withKind(value: String) : StatusDetails = copy(kind = Some(value))
  /** if kind has a value, transforms to the result of function*/
  def mapKind(f: String => String) : StatusDetails = copy(kind = kind.map(f))

  /** Returns a new data with retryAfterSeconds set to new value */
  def withRetryAfterSeconds(value: Int) : StatusDetails = copy(retryAfterSeconds = Some(value))
  /** if retryAfterSeconds has a value, transforms to the result of function*/
  def mapRetryAfterSeconds(f: Int => Int) : StatusDetails = copy(retryAfterSeconds = retryAfterSeconds.map(f))

  /** Returns a new data with group set to new value */
  def withGroup(value: String) : StatusDetails = copy(group = Some(value))
  /** if group has a value, transforms to the result of function*/
  def mapGroup(f: String => String) : StatusDetails = copy(group = group.map(f))
}

object StatusDetails {

    implicit val encoder : Encoder[io.k8s.apimachinery.pkg.apis.meta.v1.StatusDetails] = new Encoder[io.k8s.apimachinery.pkg.apis.meta.v1.StatusDetails] {
        def apply[T : Builder](o: io.k8s.apimachinery.pkg.apis.meta.v1.StatusDetails) : T = {
          val obj = ObjectWriter[T]()
          obj
            .write("name", o.name)
            .write("causes", o.causes)
            .write("uid", o.uid)
            .write("kind", o.kind)
            .write("retryAfterSeconds", o.retryAfterSeconds)
            .write("group", o.group)
            .build
        }
    }

    implicit val decoder: Decoder[StatusDetails] = new Decoder[StatusDetails] {
      def apply[T : Reader](t: T): Either[String, StatusDetails] = for {
          obj <- ObjectReader(t)
          name <- obj.readOpt[String]("name")
          causes <- obj.readOpt[Seq[io.k8s.apimachinery.pkg.apis.meta.v1.StatusCause]]("causes")
          uid <- obj.readOpt[String]("uid")
          kind <- obj.readOpt[String]("kind")
          retryAfterSeconds <- obj.readOpt[Int]("retryAfterSeconds")
          group <- obj.readOpt[String]("group")
      } yield StatusDetails (
          name = name,
          causes = causes,
          uid = uid,
          kind = kind,
          retryAfterSeconds = retryAfterSeconds,
          group = group
        )
    }
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy