{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards   #-}
{-# LANGUAGE StrictData        #-}
module GitHub.Types.Base.PullRequestRef 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 (..))

------------------------------------------------------------------------------
-- PullRequestRef

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


instance FromJSON PullRequestRef where
    parseJSON :: Value -> Parser PullRequestRef
parseJSON (Object Object
x) = Text -> Text -> Text -> Text -> PullRequestRef
PullRequestRef
        (Text -> Text -> Text -> Text -> PullRequestRef)
-> Parser Text -> Parser (Text -> Text -> Text -> PullRequestRef)
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
"url"
        Parser (Text -> Text -> Text -> PullRequestRef)
-> Parser Text -> Parser (Text -> Text -> PullRequestRef)
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
"diff_url"
        Parser (Text -> Text -> PullRequestRef)
-> Parser Text -> Parser (Text -> PullRequestRef)
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
"patch_url"
        Parser (Text -> PullRequestRef)
-> Parser Text -> Parser PullRequestRef
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
"html_url"

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


instance ToJSON PullRequestRef where
    toJSON :: PullRequestRef -> Value
toJSON PullRequestRef{Text
pullRequestRefHtmlUrl :: Text
pullRequestRefPatchUrl :: Text
pullRequestRefDiffUrl :: Text
pullRequestRefUrl :: Text
pullRequestRefHtmlUrl :: PullRequestRef -> Text
pullRequestRefPatchUrl :: PullRequestRef -> Text
pullRequestRefDiffUrl :: PullRequestRef -> Text
pullRequestRefUrl :: PullRequestRef -> Text
..} = [Pair] -> Value
object
        [ Key
"url"       Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
pullRequestRefUrl
        , Key
"diff_url"  Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
pullRequestRefDiffUrl
        , Key
"patch_url" Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
pullRequestRefPatchUrl
        , Key
"html_url"  Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
pullRequestRefHtmlUrl
        ]


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