{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeFamilies #-}

module Ouroboros.Consensus.Protocol.ModChainSel (
    ModChainSel
    -- * Type family instances
  , ConsensusConfig (..)
  ) where

import           Data.Typeable (Typeable)
import           GHC.Generics (Generic)
import           NoThunks.Class (NoThunks)
import           Ouroboros.Consensus.Protocol.Abstract

data ModChainSel p s

newtype instance ConsensusConfig (ModChainSel p s) = McsConsensusConfig {
      forall p s. ConsensusConfig (ModChainSel p s) -> ConsensusConfig p
mcsConfigP :: ConsensusConfig p
    }
  deriving ((forall x.
 ConsensusConfig (ModChainSel p s)
 -> Rep (ConsensusConfig (ModChainSel p s)) x)
-> (forall x.
    Rep (ConsensusConfig (ModChainSel p s)) x
    -> ConsensusConfig (ModChainSel p s))
-> Generic (ConsensusConfig (ModChainSel p s))
forall x.
Rep (ConsensusConfig (ModChainSel p s)) x
-> ConsensusConfig (ModChainSel p s)
forall x.
ConsensusConfig (ModChainSel p s)
-> Rep (ConsensusConfig (ModChainSel p s)) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall p s x.
Rep (ConsensusConfig (ModChainSel p s)) x
-> ConsensusConfig (ModChainSel p s)
forall p s x.
ConsensusConfig (ModChainSel p s)
-> Rep (ConsensusConfig (ModChainSel p s)) x
$cfrom :: forall p s x.
ConsensusConfig (ModChainSel p s)
-> Rep (ConsensusConfig (ModChainSel p s)) x
from :: forall x.
ConsensusConfig (ModChainSel p s)
-> Rep (ConsensusConfig (ModChainSel p s)) x
$cto :: forall p s x.
Rep (ConsensusConfig (ModChainSel p s)) x
-> ConsensusConfig (ModChainSel p s)
to :: forall x.
Rep (ConsensusConfig (ModChainSel p s)) x
-> ConsensusConfig (ModChainSel p s)
Generic)

instance ( ConsensusProtocol p
         , ChainOrder s
         , Show s
         , Typeable s
         , NoThunks s
         ) => ConsensusProtocol (ModChainSel p s) where
    type SelectView    (ModChainSel p s) = s

    type ChainDepState (ModChainSel p s) = ChainDepState p
    type IsLeader      (ModChainSel p s) = IsLeader      p
    type CanBeLeader   (ModChainSel p s) = CanBeLeader   p
    type LedgerView    (ModChainSel p s) = LedgerView    p
    type ValidationErr (ModChainSel p s) = ValidationErr p
    type ValidateView  (ModChainSel p s) = ValidateView  p

    checkIsLeader :: HasCallStack =>
ConsensusConfig (ModChainSel p s)
-> CanBeLeader (ModChainSel p s)
-> SlotNo
-> Ticked (ChainDepState (ModChainSel p s))
-> Maybe (IsLeader (ModChainSel p s))
checkIsLeader         = ConsensusConfig p
-> CanBeLeader p
-> SlotNo
-> Ticked (ChainDepState p)
-> Maybe (IsLeader p)
forall p.
(ConsensusProtocol p, HasCallStack) =>
ConsensusConfig p
-> CanBeLeader p
-> SlotNo
-> Ticked (ChainDepState p)
-> Maybe (IsLeader p)
checkIsLeader         (ConsensusConfig p
 -> CanBeLeader p
 -> SlotNo
 -> Ticked (ChainDepState p)
 -> Maybe (IsLeader p))
-> (ConsensusConfig (ModChainSel p s) -> ConsensusConfig p)
-> ConsensusConfig (ModChainSel p s)
-> CanBeLeader p
-> SlotNo
-> Ticked (ChainDepState p)
-> Maybe (IsLeader p)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ConsensusConfig (ModChainSel p s) -> ConsensusConfig p
forall p s. ConsensusConfig (ModChainSel p s) -> ConsensusConfig p
mcsConfigP
    tickChainDepState :: ConsensusConfig (ModChainSel p s)
-> LedgerView (ModChainSel p s)
-> SlotNo
-> ChainDepState (ModChainSel p s)
-> Ticked (ChainDepState (ModChainSel p s))
tickChainDepState     = ConsensusConfig p
-> LedgerView p
-> SlotNo
-> ChainDepState p
-> Ticked (ChainDepState p)
forall p.
ConsensusProtocol p =>
ConsensusConfig p
-> LedgerView p
-> SlotNo
-> ChainDepState p
-> Ticked (ChainDepState p)
tickChainDepState     (ConsensusConfig p
 -> LedgerView p
 -> SlotNo
 -> ChainDepState p
 -> Ticked (ChainDepState p))
-> (ConsensusConfig (ModChainSel p s) -> ConsensusConfig p)
-> ConsensusConfig (ModChainSel p s)
-> LedgerView p
-> SlotNo
-> ChainDepState p
-> Ticked (ChainDepState p)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ConsensusConfig (ModChainSel p s) -> ConsensusConfig p
forall p s. ConsensusConfig (ModChainSel p s) -> ConsensusConfig p
mcsConfigP
    updateChainDepState :: HasCallStack =>
ConsensusConfig (ModChainSel p s)
-> ValidateView (ModChainSel p s)
-> SlotNo
-> Ticked (ChainDepState (ModChainSel p s))
-> Except
     (ValidationErr (ModChainSel p s)) (ChainDepState (ModChainSel p s))
updateChainDepState   = ConsensusConfig p
-> ValidateView p
-> SlotNo
-> Ticked (ChainDepState p)
-> Except (ValidationErr p) (ChainDepState p)
forall p.
(ConsensusProtocol p, HasCallStack) =>
ConsensusConfig p
-> ValidateView p
-> SlotNo
-> Ticked (ChainDepState p)
-> Except (ValidationErr p) (ChainDepState p)
updateChainDepState   (ConsensusConfig p
 -> ValidateView p
 -> SlotNo
 -> Ticked (ChainDepState p)
 -> Except (ValidationErr p) (ChainDepState p))
-> (ConsensusConfig (ModChainSel p s) -> ConsensusConfig p)
-> ConsensusConfig (ModChainSel p s)
-> ValidateView p
-> SlotNo
-> Ticked (ChainDepState p)
-> Except (ValidationErr p) (ChainDepState p)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ConsensusConfig (ModChainSel p s) -> ConsensusConfig p
forall p s. ConsensusConfig (ModChainSel p s) -> ConsensusConfig p
mcsConfigP
    reupdateChainDepState :: HasCallStack =>
ConsensusConfig (ModChainSel p s)
-> ValidateView (ModChainSel p s)
-> SlotNo
-> Ticked (ChainDepState (ModChainSel p s))
-> ChainDepState (ModChainSel p s)
reupdateChainDepState = ConsensusConfig p
-> ValidateView p
-> SlotNo
-> Ticked (ChainDepState p)
-> ChainDepState p
forall p.
(ConsensusProtocol p, HasCallStack) =>
ConsensusConfig p
-> ValidateView p
-> SlotNo
-> Ticked (ChainDepState p)
-> ChainDepState p
reupdateChainDepState (ConsensusConfig p
 -> ValidateView p
 -> SlotNo
 -> Ticked (ChainDepState p)
 -> ChainDepState p)
-> (ConsensusConfig (ModChainSel p s) -> ConsensusConfig p)
-> ConsensusConfig (ModChainSel p s)
-> ValidateView p
-> SlotNo
-> Ticked (ChainDepState p)
-> ChainDepState p
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ConsensusConfig (ModChainSel p s) -> ConsensusConfig p
forall p s. ConsensusConfig (ModChainSel p s) -> ConsensusConfig p
mcsConfigP
    protocolSecurityParam :: ConsensusConfig (ModChainSel p s) -> SecurityParam
protocolSecurityParam = ConsensusConfig p -> SecurityParam
forall p. ConsensusProtocol p => ConsensusConfig p -> SecurityParam
protocolSecurityParam (ConsensusConfig p -> SecurityParam)
-> (ConsensusConfig (ModChainSel p s) -> ConsensusConfig p)
-> ConsensusConfig (ModChainSel p s)
-> SecurityParam
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ConsensusConfig (ModChainSel p s) -> ConsensusConfig p
forall p s. ConsensusConfig (ModChainSel p s) -> ConsensusConfig p
mcsConfigP

instance ConsensusProtocol p => NoThunks (ConsensusConfig (ModChainSel p s))