-- | See 'BlockSupportsMetrics'.
module Ouroboros.Consensus.Block.SupportsMetrics (
    BlockSupportsMetrics (..)
  , WhetherSelfIssued (..)
  , isSelfIssuedConstUnknown
  ) where

import           Ouroboros.Consensus.Block.Abstract

{-------------------------------------------------------------------------------
  Supported blocks
-------------------------------------------------------------------------------}

-- | Whether a block was issued by a stakeholder currently forging on this node
data WhetherSelfIssued =
    IsSelfIssued
  | IsNotSelfIssued
    -- | We are unable to determine
  | UnknownSelfIssued
  deriving (Int -> WhetherSelfIssued -> ShowS
[WhetherSelfIssued] -> ShowS
WhetherSelfIssued -> String
(Int -> WhetherSelfIssued -> ShowS)
-> (WhetherSelfIssued -> String)
-> ([WhetherSelfIssued] -> ShowS)
-> Show WhetherSelfIssued
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [WhetherSelfIssued] -> ShowS
$cshowList :: [WhetherSelfIssued] -> ShowS
show :: WhetherSelfIssued -> String
$cshow :: WhetherSelfIssued -> String
showsPrec :: Int -> WhetherSelfIssued -> ShowS
$cshowsPrec :: Int -> WhetherSelfIssued -> ShowS
Show, WhetherSelfIssued -> WhetherSelfIssued -> Bool
(WhetherSelfIssued -> WhetherSelfIssued -> Bool)
-> (WhetherSelfIssued -> WhetherSelfIssued -> Bool)
-> Eq WhetherSelfIssued
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: WhetherSelfIssued -> WhetherSelfIssued -> Bool
$c/= :: WhetherSelfIssued -> WhetherSelfIssued -> Bool
== :: WhetherSelfIssued -> WhetherSelfIssued -> Bool
$c== :: WhetherSelfIssued -> WhetherSelfIssued -> Bool
Eq)

-- | Evidence that a block supports the metrics needed for business requirements
--
-- For example, we use 'isSelfIssued' to help Stake Pool Operators monitor how
-- many of their forged blocks have not ended up on their chain.
class BlockSupportsMetrics blk where
  -- | See 'WhetherSelfIssued'.
  isSelfIssued :: BlockConfig blk -> Header blk -> WhetherSelfIssued

-- | Use this default for block types that cannot or do not yet support the
-- predicate
isSelfIssuedConstUnknown :: BlockConfig blk -> Header blk -> WhetherSelfIssued
isSelfIssuedConstUnknown :: BlockConfig blk -> Header blk -> WhetherSelfIssued
isSelfIssuedConstUnknown BlockConfig blk
_cfg Header blk
_hdr = WhetherSelfIssued
UnknownSelfIssued