{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE TypeApplications #-}

-- |
-- Copyright: © 2018-2020 IOHK
-- License: Apache-2.0
--
-- This module provides the 'RewardAccount' data type.
--
module Cardano.Wallet.Primitive.Types.RewardAccount
    ( RewardAccount (..)
    ) where

import Prelude

import Cardano.Wallet.Primitive.Types.Hash
    ( Hash (..) )
import Control.DeepSeq
    ( NFData (..) )
import Data.ByteString
    ( ByteString )
import Data.Text.Class
    ( FromText (..), ToText (..) )
import Fmt
    ( Buildable (..) )
import GHC.Generics
    ( Generic )
import Quiet
    ( Quiet (..) )

-- | A reward account is used in group-type addresses for delegation.
--
-- It is the public key of the account address.
--
newtype RewardAccount = RewardAccount { RewardAccount -> ByteString
unRewardAccount :: ByteString }
    deriving ((forall x. RewardAccount -> Rep RewardAccount x)
-> (forall x. Rep RewardAccount x -> RewardAccount)
-> Generic RewardAccount
forall x. Rep RewardAccount x -> RewardAccount
forall x. RewardAccount -> Rep RewardAccount x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RewardAccount x -> RewardAccount
$cfrom :: forall x. RewardAccount -> Rep RewardAccount x
Generic, RewardAccount -> RewardAccount -> Bool
(RewardAccount -> RewardAccount -> Bool)
-> (RewardAccount -> RewardAccount -> Bool) -> Eq RewardAccount
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RewardAccount -> RewardAccount -> Bool
$c/= :: RewardAccount -> RewardAccount -> Bool
== :: RewardAccount -> RewardAccount -> Bool
$c== :: RewardAccount -> RewardAccount -> Bool
Eq, Eq RewardAccount
Eq RewardAccount
-> (RewardAccount -> RewardAccount -> Ordering)
-> (RewardAccount -> RewardAccount -> Bool)
-> (RewardAccount -> RewardAccount -> Bool)
-> (RewardAccount -> RewardAccount -> Bool)
-> (RewardAccount -> RewardAccount -> Bool)
-> (RewardAccount -> RewardAccount -> RewardAccount)
-> (RewardAccount -> RewardAccount -> RewardAccount)
-> Ord RewardAccount
RewardAccount -> RewardAccount -> Bool
RewardAccount -> RewardAccount -> Ordering
RewardAccount -> RewardAccount -> RewardAccount
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
min :: RewardAccount -> RewardAccount -> RewardAccount
$cmin :: RewardAccount -> RewardAccount -> RewardAccount
max :: RewardAccount -> RewardAccount -> RewardAccount
$cmax :: RewardAccount -> RewardAccount -> RewardAccount
>= :: RewardAccount -> RewardAccount -> Bool
$c>= :: RewardAccount -> RewardAccount -> Bool
> :: RewardAccount -> RewardAccount -> Bool
$c> :: RewardAccount -> RewardAccount -> Bool
<= :: RewardAccount -> RewardAccount -> Bool
$c<= :: RewardAccount -> RewardAccount -> Bool
< :: RewardAccount -> RewardAccount -> Bool
$c< :: RewardAccount -> RewardAccount -> Bool
compare :: RewardAccount -> RewardAccount -> Ordering
$ccompare :: RewardAccount -> RewardAccount -> Ordering
$cp1Ord :: Eq RewardAccount
Ord)
    deriving (Int -> RewardAccount -> ShowS
[RewardAccount] -> ShowS
RewardAccount -> String
(Int -> RewardAccount -> ShowS)
-> (RewardAccount -> String)
-> ([RewardAccount] -> ShowS)
-> Show RewardAccount
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RewardAccount] -> ShowS
$cshowList :: [RewardAccount] -> ShowS
show :: RewardAccount -> String
$cshow :: RewardAccount -> String
showsPrec :: Int -> RewardAccount -> ShowS
$cshowsPrec :: Int -> RewardAccount -> ShowS
Show, ReadPrec [RewardAccount]
ReadPrec RewardAccount
Int -> ReadS RewardAccount
ReadS [RewardAccount]
(Int -> ReadS RewardAccount)
-> ReadS [RewardAccount]
-> ReadPrec RewardAccount
-> ReadPrec [RewardAccount]
-> Read RewardAccount
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RewardAccount]
$creadListPrec :: ReadPrec [RewardAccount]
readPrec :: ReadPrec RewardAccount
$creadPrec :: ReadPrec RewardAccount
readList :: ReadS [RewardAccount]
$creadList :: ReadS [RewardAccount]
readsPrec :: Int -> ReadS RewardAccount
$creadsPrec :: Int -> ReadS RewardAccount
Read) via (Quiet RewardAccount)

instance NFData RewardAccount

instance Buildable RewardAccount where
    build :: RewardAccount -> Builder
build = Hash "RewardAccount" -> Builder
forall p. Buildable p => p -> Builder
build (Hash "RewardAccount" -> Builder)
-> (RewardAccount -> Hash "RewardAccount")
-> RewardAccount
-> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Hash "RewardAccount"
forall (tag :: Symbol). ByteString -> Hash tag
Hash @"RewardAccount" (ByteString -> Hash "RewardAccount")
-> (RewardAccount -> ByteString)
-> RewardAccount
-> Hash "RewardAccount"
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RewardAccount -> ByteString
unRewardAccount

instance ToText RewardAccount where
    toText :: RewardAccount -> Text
toText = Hash "RewardAccount" -> Text
forall a. ToText a => a -> Text
toText (Hash "RewardAccount" -> Text)
-> (RewardAccount -> Hash "RewardAccount") -> RewardAccount -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Hash "RewardAccount"
forall (tag :: Symbol). ByteString -> Hash tag
Hash @"RewardAccount" (ByteString -> Hash "RewardAccount")
-> (RewardAccount -> ByteString)
-> RewardAccount
-> Hash "RewardAccount"
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RewardAccount -> ByteString
unRewardAccount

instance FromText RewardAccount where
    fromText :: Text -> Either TextDecodingError RewardAccount
fromText = (Hash "RewardAccount" -> RewardAccount)
-> Either TextDecodingError (Hash "RewardAccount")
-> Either TextDecodingError RewardAccount
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (ByteString -> RewardAccount
RewardAccount (ByteString -> RewardAccount)
-> (Hash "RewardAccount" -> ByteString)
-> Hash "RewardAccount"
-> RewardAccount
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Hash "RewardAccount" -> ByteString
forall (tag :: Symbol). Hash tag -> ByteString
getHash @"RewardAccount") (Either TextDecodingError (Hash "RewardAccount")
 -> Either TextDecodingError RewardAccount)
-> (Text -> Either TextDecodingError (Hash "RewardAccount"))
-> Text
-> Either TextDecodingError RewardAccount
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Either TextDecodingError (Hash "RewardAccount")
forall a. FromText a => Text -> Either TextDecodingError a
fromText