{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards   #-}
{-# LANGUAGE StrictData        #-}
module GitHub.Types.Base.UserStamp where

import           Data.Aeson                (FromJSON (..), ToJSON (..), object)
import           Data.Aeson.Types          (Value (..), (.:), (.=))
import           Data.Text                 (Text)
import           Data.Text.Arbitrary       ()
import           Test.QuickCheck.Arbitrary (Arbitrary (..))

------------------------------------------------------------------------------
-- UserStamp

data UserStamp = UserStamp
    { UserStamp -> Text
userStampName  :: Text
    , UserStamp -> Text
userStampEmail :: Text
    , UserStamp -> Text
userStampDate  :: Text
    } deriving (UserStamp -> UserStamp -> Bool
(UserStamp -> UserStamp -> Bool)
-> (UserStamp -> UserStamp -> Bool) -> Eq UserStamp
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UserStamp -> UserStamp -> Bool
$c/= :: UserStamp -> UserStamp -> Bool
== :: UserStamp -> UserStamp -> Bool
$c== :: UserStamp -> UserStamp -> Bool
Eq, Int -> UserStamp -> ShowS
[UserStamp] -> ShowS
UserStamp -> String
(Int -> UserStamp -> ShowS)
-> (UserStamp -> String)
-> ([UserStamp] -> ShowS)
-> Show UserStamp
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UserStamp] -> ShowS
$cshowList :: [UserStamp] -> ShowS
show :: UserStamp -> String
$cshow :: UserStamp -> String
showsPrec :: Int -> UserStamp -> ShowS
$cshowsPrec :: Int -> UserStamp -> ShowS
Show, ReadPrec [UserStamp]
ReadPrec UserStamp
Int -> ReadS UserStamp
ReadS [UserStamp]
(Int -> ReadS UserStamp)
-> ReadS [UserStamp]
-> ReadPrec UserStamp
-> ReadPrec [UserStamp]
-> Read UserStamp
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UserStamp]
$creadListPrec :: ReadPrec [UserStamp]
readPrec :: ReadPrec UserStamp
$creadPrec :: ReadPrec UserStamp
readList :: ReadS [UserStamp]
$creadList :: ReadS [UserStamp]
readsPrec :: Int -> ReadS UserStamp
$creadsPrec :: Int -> ReadS UserStamp
Read)


instance FromJSON UserStamp where
    parseJSON :: Value -> Parser UserStamp
parseJSON (Object Object
x) = Text -> Text -> Text -> UserStamp
UserStamp
        (Text -> Text -> Text -> UserStamp)
-> Parser Text -> Parser (Text -> Text -> UserStamp)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
x Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"name"
        Parser (Text -> Text -> UserStamp)
-> Parser Text -> Parser (Text -> UserStamp)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
x Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"email"
        Parser (Text -> UserStamp) -> Parser Text -> Parser UserStamp
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
x Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"date"

    parseJSON Value
_ = String -> Parser UserStamp
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"UserStamp"


instance ToJSON UserStamp where
    toJSON :: UserStamp -> Value
toJSON UserStamp{Text
userStampDate :: Text
userStampEmail :: Text
userStampName :: Text
userStampDate :: UserStamp -> Text
userStampEmail :: UserStamp -> Text
userStampName :: UserStamp -> Text
..} = [Pair] -> Value
object
        [ Key
"name"  Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
userStampName
        , Key
"email" Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
userStampEmail
        , Key
"date"  Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
userStampDate
        ]


instance Arbitrary UserStamp where
    arbitrary :: Gen UserStamp
arbitrary = Text -> Text -> Text -> UserStamp
UserStamp
        (Text -> Text -> Text -> UserStamp)
-> Gen Text -> Gen (Text -> Text -> UserStamp)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Text
forall a. Arbitrary a => Gen a
arbitrary
        Gen (Text -> Text -> UserStamp)
-> Gen Text -> Gen (Text -> UserStamp)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Text
forall a. Arbitrary a => Gen a
arbitrary
        Gen (Text -> UserStamp) -> Gen Text -> Gen UserStamp
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Text
forall a. Arbitrary a => Gen a
arbitrary