{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
module GitHub.Types.Base.Change 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 (..))
newtype Change = Change
{ Change -> Text
changesFrom :: Text
} deriving (Change -> Change -> Bool
(Change -> Change -> Bool)
-> (Change -> Change -> Bool) -> Eq Change
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Change -> Change -> Bool
$c/= :: Change -> Change -> Bool
== :: Change -> Change -> Bool
$c== :: Change -> Change -> Bool
Eq, Int -> Change -> ShowS
[Change] -> ShowS
Change -> String
(Int -> Change -> ShowS)
-> (Change -> String) -> ([Change] -> ShowS) -> Show Change
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Change] -> ShowS
$cshowList :: [Change] -> ShowS
show :: Change -> String
$cshow :: Change -> String
showsPrec :: Int -> Change -> ShowS
$cshowsPrec :: Int -> Change -> ShowS
Show, ReadPrec [Change]
ReadPrec Change
Int -> ReadS Change
ReadS [Change]
(Int -> ReadS Change)
-> ReadS [Change]
-> ReadPrec Change
-> ReadPrec [Change]
-> Read Change
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Change]
$creadListPrec :: ReadPrec [Change]
readPrec :: ReadPrec Change
$creadPrec :: ReadPrec Change
readList :: ReadS [Change]
$creadList :: ReadS [Change]
readsPrec :: Int -> ReadS Change
$creadsPrec :: Int -> ReadS Change
Read)
instance FromJSON Change where
parseJSON :: Value -> Parser Change
parseJSON (Object Object
x) = Text -> Change
Change
(Text -> Change) -> Parser Text -> Parser Change
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
"from"
parseJSON Value
_ = String -> Parser Change
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Change"
instance ToJSON Change where
toJSON :: Change -> Value
toJSON Change{Text
changesFrom :: Text
changesFrom :: Change -> Text
..} = [Pair] -> Value
object
[ Key
"from" Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
changesFrom
]
instance Arbitrary Change where
arbitrary :: Gen Change
arbitrary = Text -> Change
Change
(Text -> Change) -> Gen Text -> Gen Change
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Text
forall a. Arbitrary a => Gen a
arbitrary