module LaunchDarkly.Server.Client.Status
    ( Status (..)
    , transitionStatus
    )
where

-- | The status of the client initialization.
data Status
    = -- | The client has not yet finished connecting to LaunchDarkly.
      Uninitialized
    | -- | The client attempted to connect to LaunchDarkly and was denied.
      Unauthorized
    | -- | The client has successfuly connected to LaunchDarkly.
      Initialized
    | -- | The client is being terminated
      ShuttingDown
    deriving (Int -> Status -> ShowS
[Status] -> ShowS
Status -> String
(Int -> Status -> ShowS)
-> (Status -> String) -> ([Status] -> ShowS) -> Show Status
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Status] -> ShowS
$cshowList :: [Status] -> ShowS
show :: Status -> String
$cshow :: Status -> String
showsPrec :: Int -> Status -> ShowS
$cshowsPrec :: Int -> Status -> ShowS
Show, Status -> Status -> Bool
(Status -> Status -> Bool)
-> (Status -> Status -> Bool) -> Eq Status
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Status -> Status -> Bool
$c/= :: Status -> Status -> Bool
== :: Status -> Status -> Bool
$c== :: Status -> Status -> Bool
Eq)

transitionStatus :: Status -> Status -> Status
transitionStatus :: Status -> Status -> Status
transitionStatus requestedStatus :: Status
requestedStatus oldStatus :: Status
oldStatus =
    case Status
requestedStatus of
        -- Only allow setting Initialized if Uninitialized
        Initialized -> if Status
oldStatus Status -> Status -> Bool
forall a. Eq a => a -> a -> Bool
== Status
Uninitialized then Status
Initialized else Status
oldStatus
        -- Only allow setting status if not ShuttingDown
        _ -> if Status
oldStatus Status -> Status -> Bool
forall a. Eq a => a -> a -> Bool
== Status
ShuttingDown then Status
ShuttingDown else Status
requestedStatus