{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
module GitHub.Types.Base.Changes where
import Data.Aeson (FromJSON (..), ToJSON (..), object)
import Data.Aeson.Types (Value (..), (.:?), (.=))
import Test.QuickCheck.Arbitrary (Arbitrary (..))
import GitHub.Types.Base.Change
data Changes = Changes
{ Changes -> Maybe Change
changesTitle :: Maybe Change
, Changes -> Maybe Change
changesBody :: Maybe Change
} deriving (Changes -> Changes -> Bool
(Changes -> Changes -> Bool)
-> (Changes -> Changes -> Bool) -> Eq Changes
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Changes -> Changes -> Bool
$c/= :: Changes -> Changes -> Bool
== :: Changes -> Changes -> Bool
$c== :: Changes -> Changes -> Bool
Eq, Int -> Changes -> ShowS
[Changes] -> ShowS
Changes -> String
(Int -> Changes -> ShowS)
-> (Changes -> String) -> ([Changes] -> ShowS) -> Show Changes
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Changes] -> ShowS
$cshowList :: [Changes] -> ShowS
show :: Changes -> String
$cshow :: Changes -> String
showsPrec :: Int -> Changes -> ShowS
$cshowsPrec :: Int -> Changes -> ShowS
Show, ReadPrec [Changes]
ReadPrec Changes
Int -> ReadS Changes
ReadS [Changes]
(Int -> ReadS Changes)
-> ReadS [Changes]
-> ReadPrec Changes
-> ReadPrec [Changes]
-> Read Changes
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Changes]
$creadListPrec :: ReadPrec [Changes]
readPrec :: ReadPrec Changes
$creadPrec :: ReadPrec Changes
readList :: ReadS [Changes]
$creadList :: ReadS [Changes]
readsPrec :: Int -> ReadS Changes
$creadsPrec :: Int -> ReadS Changes
Read)
instance FromJSON Changes where
parseJSON :: Value -> Parser Changes
parseJSON (Object Object
x) = Maybe Change -> Maybe Change -> Changes
Changes
(Maybe Change -> Maybe Change -> Changes)
-> Parser (Maybe Change) -> Parser (Maybe Change -> Changes)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
x Object -> Key -> Parser (Maybe Change)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"title"
Parser (Maybe Change -> Changes)
-> Parser (Maybe Change) -> Parser Changes
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
x Object -> Key -> Parser (Maybe Change)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"body"
parseJSON Value
_ = String -> Parser Changes
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Changes"
instance ToJSON Changes where
toJSON :: Changes -> Value
toJSON Changes{Maybe Change
changesBody :: Maybe Change
changesTitle :: Maybe Change
changesBody :: Changes -> Maybe Change
changesTitle :: Changes -> Maybe Change
..} = [Pair] -> Value
object
[ Key
"title" Key -> Maybe Change -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Change
changesTitle
, Key
"body" Key -> Maybe Change -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Change
changesBody
]
instance Arbitrary Changes where
arbitrary :: Gen Changes
arbitrary = Maybe Change -> Maybe Change -> Changes
Changes
(Maybe Change -> Maybe Change -> Changes)
-> Gen (Maybe Change) -> Gen (Maybe Change -> Changes)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen (Maybe Change)
forall a. Arbitrary a => Gen a
arbitrary
Gen (Maybe Change -> Changes) -> Gen (Maybe Change) -> Gen Changes
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen (Maybe Change)
forall a. Arbitrary a => Gen a
arbitrary