module Cardano.Wallet.Primitive.Types.RewardAccount.Gen
    ( genRewardAccount
    , shrinkRewardAccount
    )
    where

import Prelude

import Cardano.Wallet.Primitive.Types.RewardAccount
    ( RewardAccount (..) )
import Test.QuickCheck
    ( Gen, elements, sized )

import qualified Data.ByteString.Char8 as B8

--------------------------------------------------------------------------------
-- Reward accounts generated according to the size parameter
--------------------------------------------------------------------------------

genRewardAccount :: Gen (RewardAccount)
genRewardAccount :: Gen RewardAccount
genRewardAccount = (Int -> Gen RewardAccount) -> Gen RewardAccount
forall a. (Int -> Gen a) -> Gen a
sized ((Int -> Gen RewardAccount) -> Gen RewardAccount)
-> (Int -> Gen RewardAccount) -> Gen RewardAccount
forall a b. (a -> b) -> a -> b
$ \Int
size -> [RewardAccount] -> Gen RewardAccount
forall a. [a] -> Gen a
elements ([RewardAccount] -> Gen RewardAccount)
-> [RewardAccount] -> Gen RewardAccount
forall a b. (a -> b) -> a -> b
$ Int -> [RewardAccount] -> [RewardAccount]
forall a. Int -> [a] -> [a]
take (Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
1 Int
size) [RewardAccount]
addresses

shrinkRewardAccount :: RewardAccount -> [RewardAccount]
shrinkRewardAccount :: RewardAccount -> [RewardAccount]
shrinkRewardAccount RewardAccount
a
    | RewardAccount
a RewardAccount -> RewardAccount -> Bool
forall a. Eq a => a -> a -> Bool
== RewardAccount
simplest = []
    | Bool
otherwise = [RewardAccount
simplest]
  where
    simplest :: RewardAccount
simplest = [RewardAccount] -> RewardAccount
forall a. [a] -> a
head [RewardAccount]
addresses

addresses :: [RewardAccount]
addresses :: [RewardAccount]
addresses = Char -> RewardAccount
mkRewardAccount (Char -> RewardAccount) -> [Char] -> [RewardAccount]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Char
'0' ..]

--------------------------------------------------------------------------------
-- Internal utilities
--------------------------------------------------------------------------------

mkRewardAccount :: Char -> RewardAccount
mkRewardAccount :: Char -> RewardAccount
mkRewardAccount Char
c = ByteString -> RewardAccount
RewardAccount (ByteString -> RewardAccount) -> ByteString -> RewardAccount
forall a b. (a -> b) -> a -> b
$ ByteString
"Reward" ByteString -> Char -> ByteString
`B8.snoc` Char
c