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

lucuma.core.enums.ObsActiveStatus.scala Maven / Gradle / Ivy

There is a newer version: 0.108.0
Show newest version
// Copyright (c) 2016-2023 Association of Universities for Research in Astronomy, Inc. (AURA)
// For license information see LICENSE or https://opensource.org/licenses/BSD-3-Clause

package lucuma.core.enums

import lucuma.core.util.Display
import lucuma.core.util.Enumerated
import monocle.Iso

/**
 * Determines whether an observation should be considered active.  It, for
 * example, "allows PIs to prevent or halt execution of "Ready'' or "Ongoing''
 * observations while retaining their status information".
 */
sealed abstract class ObsActiveStatus(val tag: String, val label: String, val toBoolean: Boolean) extends Product with Serializable {

  def fold[A](active: => A, inactive: => A): A =
    this match {
      case ObsActiveStatus.Active   => active
      case ObsActiveStatus.Inactive => inactive
    }

}

object ObsActiveStatus {

  case object Active   extends ObsActiveStatus("active", "Active", true)
  case object Inactive extends ObsActiveStatus("inactive", "Inactive", false)

  /** @group Typeclass Instances */
  implicit val EnumeratedObsActiveStatus: Enumerated[ObsActiveStatus] =
    Enumerated.from(
      Active,
      Inactive
    ).withTag(_.tag)

  implicit val DisplayObsActiveStatus: Display[ObsActiveStatus] =
    Display.byShortName(_.label)

  val FromBoolean: Iso[Boolean, ObsActiveStatus] =
    Iso[Boolean, ObsActiveStatus](b => if (b) Active else Inactive)(_.toBoolean)

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy