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