{-# LANGUAGE DeriveGeneric              #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE StrictData                 #-}
module Network.Tox.SaveData.Nodes
    ( Nodes (..)
    ) where

import           Data.Binary                   (Binary (..))
import           Data.MessagePack              (MessagePack)
import           GHC.Generics                  (Generic)
import           Network.Tox.NodeInfo.NodeInfo (NodeInfo)
import qualified Network.Tox.SaveData.Util     as Util
import           Test.QuickCheck.Arbitrary     (Arbitrary, arbitrary)

newtype Nodes = Nodes [NodeInfo]
    deriving (Nodes -> Nodes -> Bool
(Nodes -> Nodes -> Bool) -> (Nodes -> Nodes -> Bool) -> Eq Nodes
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Nodes -> Nodes -> Bool
$c/= :: Nodes -> Nodes -> Bool
== :: Nodes -> Nodes -> Bool
$c== :: Nodes -> Nodes -> Bool
Eq, Int -> Nodes -> ShowS
[Nodes] -> ShowS
Nodes -> String
(Int -> Nodes -> ShowS)
-> (Nodes -> String) -> ([Nodes] -> ShowS) -> Show Nodes
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Nodes] -> ShowS
$cshowList :: [Nodes] -> ShowS
show :: Nodes -> String
$cshow :: Nodes -> String
showsPrec :: Int -> Nodes -> ShowS
$cshowsPrec :: Int -> Nodes -> ShowS
Show, ReadPrec [Nodes]
ReadPrec Nodes
Int -> ReadS Nodes
ReadS [Nodes]
(Int -> ReadS Nodes)
-> ReadS [Nodes]
-> ReadPrec Nodes
-> ReadPrec [Nodes]
-> Read Nodes
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Nodes]
$creadListPrec :: ReadPrec [Nodes]
readPrec :: ReadPrec Nodes
$creadPrec :: ReadPrec Nodes
readList :: ReadS [Nodes]
$creadList :: ReadS [Nodes]
readsPrec :: Int -> ReadS Nodes
$creadsPrec :: Int -> ReadS Nodes
Read, (forall x. Nodes -> Rep Nodes x)
-> (forall x. Rep Nodes x -> Nodes) -> Generic Nodes
forall x. Rep Nodes x -> Nodes
forall x. Nodes -> Rep Nodes x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Nodes x -> Nodes
$cfrom :: forall x. Nodes -> Rep Nodes x
Generic)

instance MessagePack Nodes

instance Binary Nodes where
    get :: Get Nodes
get = [NodeInfo] -> Nodes
Nodes ([NodeInfo] -> Nodes) -> Get [NodeInfo] -> Get Nodes
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get [NodeInfo]
forall a. (Binary a, Show a) => Get [a]
Util.getList
    put :: Nodes -> Put
put (Nodes [NodeInfo]
xs) = (NodeInfo -> Put) -> [NodeInfo] -> Put
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ NodeInfo -> Put
forall t. Binary t => t -> Put
put [NodeInfo]
xs

instance Arbitrary Nodes where
    arbitrary :: Gen Nodes
arbitrary = [NodeInfo] -> Nodes
Nodes ([NodeInfo] -> Nodes) -> Gen [NodeInfo] -> Gen Nodes
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen [NodeInfo]
forall a. Arbitrary a => Gen a
arbitrary