{-# LANGUAGE DeriveGeneric              #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE NoImplicitPrelude          #-}
{-# LANGUAGE StrictData                 #-}

module Data.Raft.NodeIdentifier where

import           Data.RaftPrelude

newtype NodeIdentifier a = NodeIdentifier a
  deriving (Eq, Ord, Show, Generic, Typeable, Hashable)

-- | Identifier representing the self node.
type Self a = NodeIdentifier a

-- | Identifier representing the current leader node.
type Leader a = NodeIdentifier a

-- | Identifier representing a candidate node.
type Candidate a = NodeIdentifier a

-- | Identifier representing a peer node.
type Peer a = NodeIdentifier a

-- | Identifier of a client which makes requests of the cluster.
type Client a = NodeIdentifier a

-- | Identifier representing the node that was voted for.
data Supporting a
  = Supporting (NodeIdentifier a)
  | Undecided
  deriving (Eq, Ord, Show, Generic, Typeable)

instance (Hashable a) => Hashable (Supporting a)

instance Default (Supporting a) where
  def = Undecided
