{-# LANGUAGE DeriveAnyClass     #-}
{-# LANGUAGE DeriveGeneric      #-}
{-# LANGUAGE DerivingStrategies #-}

module Ouroboros.Network.PerasSupport
  ( PerasSupport (..)
  , perasSupportToBool
  , perasSupportFromBool
  ) where

import Control.DeepSeq (NFData)
import GHC.Generics (Generic)

-- | The flag which indicates whether the node can support Peras protocol.
--
-- It is communicated via 'NodeToNodeVersionData' during handshake
-- negotiation. If both the local and remote nodes support Peras protocol,
-- then Peras protocol can be used.

data PerasSupport = PerasUnsupported | PerasSupported
  deriving stock    (PerasSupport -> PerasSupport -> Bool
(PerasSupport -> PerasSupport -> Bool)
-> (PerasSupport -> PerasSupport -> Bool) -> Eq PerasSupport
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PerasSupport -> PerasSupport -> Bool
== :: PerasSupport -> PerasSupport -> Bool
$c/= :: PerasSupport -> PerasSupport -> Bool
/= :: PerasSupport -> PerasSupport -> Bool
Eq, Eq PerasSupport
Eq PerasSupport =>
(PerasSupport -> PerasSupport -> Ordering)
-> (PerasSupport -> PerasSupport -> Bool)
-> (PerasSupport -> PerasSupport -> Bool)
-> (PerasSupport -> PerasSupport -> Bool)
-> (PerasSupport -> PerasSupport -> Bool)
-> (PerasSupport -> PerasSupport -> PerasSupport)
-> (PerasSupport -> PerasSupport -> PerasSupport)
-> Ord PerasSupport
PerasSupport -> PerasSupport -> Bool
PerasSupport -> PerasSupport -> Ordering
PerasSupport -> PerasSupport -> PerasSupport
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: PerasSupport -> PerasSupport -> Ordering
compare :: PerasSupport -> PerasSupport -> Ordering
$c< :: PerasSupport -> PerasSupport -> Bool
< :: PerasSupport -> PerasSupport -> Bool
$c<= :: PerasSupport -> PerasSupport -> Bool
<= :: PerasSupport -> PerasSupport -> Bool
$c> :: PerasSupport -> PerasSupport -> Bool
> :: PerasSupport -> PerasSupport -> Bool
$c>= :: PerasSupport -> PerasSupport -> Bool
>= :: PerasSupport -> PerasSupport -> Bool
$cmax :: PerasSupport -> PerasSupport -> PerasSupport
max :: PerasSupport -> PerasSupport -> PerasSupport
$cmin :: PerasSupport -> PerasSupport -> PerasSupport
min :: PerasSupport -> PerasSupport -> PerasSupport
Ord, Int -> PerasSupport -> ShowS
[PerasSupport] -> ShowS
PerasSupport -> String
(Int -> PerasSupport -> ShowS)
-> (PerasSupport -> String)
-> ([PerasSupport] -> ShowS)
-> Show PerasSupport
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PerasSupport -> ShowS
showsPrec :: Int -> PerasSupport -> ShowS
$cshow :: PerasSupport -> String
show :: PerasSupport -> String
$cshowList :: [PerasSupport] -> ShowS
showList :: [PerasSupport] -> ShowS
Show, PerasSupport
PerasSupport -> PerasSupport -> Bounded PerasSupport
forall a. a -> a -> Bounded a
$cminBound :: PerasSupport
minBound :: PerasSupport
$cmaxBound :: PerasSupport
maxBound :: PerasSupport
Bounded, (forall x. PerasSupport -> Rep PerasSupport x)
-> (forall x. Rep PerasSupport x -> PerasSupport)
-> Generic PerasSupport
forall x. Rep PerasSupport x -> PerasSupport
forall x. PerasSupport -> Rep PerasSupport x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. PerasSupport -> Rep PerasSupport x
from :: forall x. PerasSupport -> Rep PerasSupport x
$cto :: forall x. Rep PerasSupport x -> PerasSupport
to :: forall x. Rep PerasSupport x -> PerasSupport
Generic)
  deriving anyclass (PerasSupport -> ()
(PerasSupport -> ()) -> NFData PerasSupport
forall a. (a -> ()) -> NFData a
$crnf :: PerasSupport -> ()
rnf :: PerasSupport -> ()
NFData)


perasSupportToBool :: PerasSupport -> Bool
perasSupportToBool :: PerasSupport -> Bool
perasSupportToBool PerasSupport
PerasUnsupported = Bool
False
perasSupportToBool PerasSupport
PerasSupported   = Bool
True

perasSupportFromBool :: Bool -> PerasSupport
perasSupportFromBool :: Bool -> PerasSupport
perasSupportFromBool Bool
False = PerasSupport
PerasUnsupported
perasSupportFromBool Bool
True  = PerasSupport
PerasSupported